Reputation: 3028
im trying to get an element using jquery who has a certain class and also a specific value which only one of the elements who have that class have. for example
<div class="asd" value="a"></div>
out of :
<div class="asd"></div>
<div class="asd"></div>
<div class="asd"></div>
<div class="asd"></div>
so far i tried something like : $(".mainCss[value=yay]").index()
yay is a string object.
Upvotes: 0
Views: 108
Reputation: 46349
Your issue is not what you think it is. You seem to be confused about how to put a string object inside a selector. What you intended is (probably) this:
$(".mainCss[value='"+yay+"']").index()
which will put the value of the variable yay
into the selector. If this variable is unconstrained, you should escape it too.
Upvotes: 2
Reputation: 9580
$(".mainCss[value='a']").index()
is more spefically what you wanted to select the div in the question you have the code right though
Upvotes: 0
Reputation: 624
$(".mainCss[value='yay']").index()
you need to surround the value with single quotes.
Upvotes: 1