I created leaflet map, when you hover the marker in popup window is a reference to the content. enter image description here

I wrote module that loads ajax content in the custom region. For dynamic links added class use-ajax, but Drupal does not process them as I needed. I check and found that static links with class use-ajax have additional class ajax-processing. My dynamic link looks like:

<a id="jslink" class="use-ajax" href="nojs/problem/83">засорение реки</a>

Static link looks like:

<a class="use-ajax ajax-processed" href="nojs/node/231">node</a>

As I understand Ajax Drupal does not work with dynamic links. I found issue in what asks in what need to change the href attribute of a link and make the ajax call to the new url. Change 'href' attribute in AJAX enabled links Wrote JS code but it doesn't work for me.

(function ($) {
  Drupal.behaviors.test_module = {
    attach: function (context, settings) {
            var href = $("#jslink").attr("href");
            Drupal.ajax['jslink'].options.url = href;


Is it possible to somehow make Drupal to work with dynamic links? What am I doing wrong?

  • What is the actual question here?
    – Kevin
    Commented Mar 4, 2017 at 18:46
  • @Kevin Question is how to do so ajax started working with dynamically created links?
    – makbuk
    Commented Mar 4, 2017 at 19:39

1 Answer 1


I found solution, for loading balloons I use module IP Geolocation Views & Maps it has js file ip_geoloc_leaflet_goto_content_on_click.js where I add line Drupal.attachBehaviors(); Now it works as designed.

jQuery(document).bind('leaflet.feature', function(event, marker, feature) {
  // marker is the feature just added to the map, it could be a polygon too.
  // feature.feature_id is the node ID, as set by ip_geoloc_plugin_style_leaflet.inc
  // Need to set this up for code below.
  // The same code is used for cross-highlighting. See ip_geoloc_leaflet_sync_content.js
  if (feature.feature_id) {
    marker.feature_id = feature.feature_id;

jQuery(document).bind('leaflet.map', function(event, map, lMap) {

  if (map.settings.gotoContentOnClick) {
    for (var leaflet_id in lMap._layers) {
      lMap._layers[leaflet_id].on('click', function(e) {
        var id = e.target ? e.target.feature_id : null;
        if (!id && e.layer) id = e.layer.feature_id;
        if (id) {
            //document.location.href = Drupal.settings.basePath + 'node/' + id;
            document.location.href = Drupal.settings.basePath + 'load_node/' + id;
  if (map.settings.openBalloonsOnHover) {
    for (var leaflet_id in lMap._layers) {
      lMap._layers[leaflet_id].on('mouseover', function(e) {
         Drupal.attachBehaviors(); <<<<--------ADDED LINE


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.