gruber
gruber

Reputation: 29737

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?

Upvotes: 0

Views: 103

Answers (3)

Jishnu A P
Jishnu A P

Reputation: 14382

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

Upvotes: 1

Mike Thomsen
Mike Thomsen

Reputation: 37506

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

Upvotes: 3

detaylor
detaylor

Reputation: 7280

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 + ']').

Upvotes: 1

Related Questions