开发者

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

开发者 https://www.devze.com 2023-03-01 12:46 出处:网络
var obj = document.getElementById(\"<开发者_如何学运维;%= tbUpdate.ClientID %>\"); var colorid = obj.value;
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

精彩评论

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

关注公众号