-1

I have created a glossary view which shows alphabetical navigation to filter the list.

But I can't find a way to highlight the active link - would like for "G" to be highlighted if I am clicking the "G".

I have this tutorial for this but it works only when ajax is disabled. But I am using ajax for this glossary view.

Below is the code which isn't working

$(".view-display-id-attachment_1 span a").each(function(){
     if($(this).attr("href") == location.pathname) {
       $(this).addClass('my-class');
     }
});

I want something like this

enter image description here

When C will be clicked it will be highlighted this way

How will I achieve this in view glossary when ajax is enabled?

Thanks in advance.

Please check the issue I am facing currently. Click Here

4
  • 1
    Is that code inside of an attach property as shown in the JavaScript API docs? drupal.org/docs/drupal-apis/javascript-api/… If it is not, it should be.
    – cilefen
    Dec 21, 2022 at 15:10
  • 1
    Does this answer your question? Better understanding of Drupal behaviors
    – cilefen
    Dec 21, 2022 at 15:14
  • @cilefen that code is working if the glossary is not ajax enabled. But my glossary view is Ajax enabled. Though as per your suggestion I added this code Drupal.behaviors.mymodule = {attach: function (context, settings) {$('#.view-display-id-attachment_1 span a', context).change(function () {alert('hi');});}};. But its not working.
    – Souvik Das
    Dec 21, 2022 at 16:37
  • @cilefen I have edited my question and added a link to show the problem I am facing.
    – Souvik Das
    Dec 23, 2022 at 7:10

1 Answer 1

0

After so many research I understood that unfortunately glossary view doesn't add is-active class if AJAX enabled in the view.  

So I had to use a contrib module for that. It provides a simple A-Z filter as radio button/checkbox.

https://www.drupal.org/project/custom_view_filters

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.