Jquery get class name and store as variable
I'm trying to make a variable that grabs a class name from a link that exists. Then Im trying to add that variable to another element.
https://gist.github.com/7开发者_Python百科88460
Your variable definition is scoped inside the click event's function. Do this instead:
var $myClass, $filterAlpha, $filterBeta;
$("ul ul li a").click(function() {
$myClass = $(this).attr("class");
});
$filterAlpha = $('#alpha ul li a').addClass($myClass);
$filterBeta = $('#beta ul li a').addClass($myClass);
精彩评论