Score:-1

How will I highlight active item in glossary view?

rs flag

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

id flag
Is that code inside of an attach property as shown in the JavaScript API docs? https://www.drupal.org/docs/drupal-apis/javascript-api/javascript-api-overview If it is not, it should be.
id flag
Does this answer your question? [Better understanding of Drupal behaviors](https://drupal.stackexchange.com/questions/11756/better-understanding-of-drupal-behaviors)
Souvik Das avatar
rs flag
@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 avatar
rs flag
@cilefen I have edited my question and added a link to show the problem I am facing.
Score:0
rs flag

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

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.