0

I know, for links to be ajaxified they need to have a class: "use-ajax" and a proper url which has its own callback. For example:

<a href="ajax-reader/nojs/1/2015-03-05" class="use-ajax ajax-processed">Ajax Link</a>

If the link was statically created on the server, it works perfectly fine. But whenever I add a new link with the same properties, ajax seems not to work anymore. For instance, if I remove existing link and add a new one with new url parameters:

var ajaxRightUrl = 'ajax-reader/nojs/1/' + lastNextDate;
arrowLinkLeft.find('a').remove();
arrowLinkLeft.append('<a href="' + ajaxRightUrl + '"class="use-ajax"></a>');

It stops being an ajax link. Any ideas why?

1 Answer 1

1

you are probably missing the part to add behaviors to your new elements:

Drupal.attachBehaviors('.use-ajax');
1
  • Very good, that was it! I had the above code in a separate function outside attach: function (context, settings) So, I had to pass context parameter to my function and use it in your code: Drupal.attachBehaviors('.use-ajax', context); Thanks very much! Mar 29, 2015 at 15:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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