开发者

jQuery selector: How can I pass value from var colorid into selector?

var obj = document.getElementById("<开发者_如何学运维;%= tbUpdate.ClientID %>");
    var colorid = obj.value;
    $('.shade[colorId=colorid]').addClass('active');

the problem is with the colorId=colorid. I think jQuery thinks that it's string. How can I pass value from var colorid into selector?


$('.shade[colorId=' + colorid + ']');


If you want to use the value of colorId you would need to pass a string to the jQuery selector using concatenation$('.shade[colorId=' + colorid + ']').


$('.shade[colorId=' + colorid + ']').addClass('active');
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜