Reputation: 399
Is it possible to find a span using jquery selector similar to selecting an input like this
$("input[value=boo]").parent().addClass("red");
I've tried with replacing value with text, content and other things without success.
Upvotes: 0
Views: 280
Reputation: 144689
You can use filter
method:
$("span").filter(function() {
var txt = this.textContent || this.innerText;
// var txt = $(this).text();
return txt === 'boo';
}).parent().addClass("red");
Upvotes: 1
Reputation: 74738
Suppose this is your span:
<span class='span-1'>Text of span.</span>
then:
$('span[class^="span"]').addClass('red');
Upvotes: 0
Reputation: 903
Sure thing. You can do something like $("span[name='test']").parent().addClass("red");
or $("span[id='test']")
and it'll work.
Upvotes: 1