Constanta
Constanta

Reputation: 399

jquery span value selector

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

Answers (3)

Ram
Ram

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

Jai
Jai

Reputation: 74738

Suppose this is your span:

<span class='span-1'>Text of span.</span>

then:

$('span[class^="span"]').addClass('red');

Upvotes: 0

C.O.D.E
C.O.D.E

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

Related Questions