javascript - How to reference an element in a list from another list with with the same class (the class is a variable)? -


i have 2 lists on website. each element has corresponding class in other list. click element in dl, , ul element add new class. thought it, apparently not:

$('dl dt').click(function () {     var classname = $(this).attr('class');     $('dl dt[class~=classname]').click(function() {         $("ul li").removeclass('active');         $('ul li[class~=classname]').addclass('active');     }); }) 

i feel pretty dumb because seems super easy accomplish, can't quite it. forgive me if missed obvious answer elsewhere on site; looked while , couldn't find anything.

you need modify selector:

$('dl dt[class~="'+classname+'"]').click(function() {     $("ul li").removeclass('active');     $('ul li[class~="'+classname+'"]').addclass('active'); }); 

like adeneo said, if have more 1 class, return classes!


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -