Получить значение данных, если элемент имеет активный класс динамическиJquery

Программирование на jquery
Ответить
Гость
 Получить значение данных, если элемент имеет активный класс динамически

Сообщение Гость »


I have html that has a different data-value set

Код: Выделить всё

[*]     option 1 (3)  
I am trying to set a dynamic variable to store the data-value depending on what list item is active.

This is what I have tried

Код: Выделить всё

jQuery("li.a").each(function () {   // loop through all li a   if (jQuery(this).hasClass("active")) {     // check if li a has active class     console.log($(this).data("value")); // get the value of data-interest attribute   } }); 
I also have this:

Код: Выделить всё

var itemType = jQuery("ul.filter-list").find("li.active").data("itemtype"); alert(itemType); 
When I click a new item in the menu it does not refresh the data. I need a way for the data-value to update on the click of a new menu item.

UPDATE

How to have this re run when a option is selected

Код: Выделить всё

let active = jQuery(".active") let itemType = jQuery('ul.filter-list').find("ul li .active").data('itemtype'); console.log(itemType); 
option

Код: Выделить всё

[*]term_id; ?> ? 'child' : ''" ;>                      

Источник: [url]https://stackoverflow.com/questions/78125110/get-data-value-if-a-element-has-active-class-dynamically[/url]
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Jquery»