开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜