I have html that has a different data-value set
Код: Выделить всё
[*] option 1 (3) 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 } }); Код: Выделить всё
var itemType = jQuery("ul.filter-list").find("li.active").data("itemtype"); alert(itemType); 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); Код: Выделить всё
[*]term_id; ?> ? 'child' : ''" ;>
Источник: [url]https://stackoverflow.com/questions/78125110/get-data-value-if-a-element-has-active-class-dynamically[/url]
Мобильная версия