Marleyzs
Marleyzs

Reputation: 155

Jquery selector with specific innerHTML

$('.select option:selected[innerHTML="5"]')

My goal here is to select an option which is currently selected and which's innerHTML matches exactly a string (example : "5")

Here's a fiddle : http://jsfiddle.net/kxkzU/4/

This : $('.select option:selected:contains("5")') does not work since then value 0.375 would match.

Upvotes: 0

Views: 2389

Answers (1)

Kevin B
Kevin B

Reputation: 95054

Use filter:

$('.select option:selected').filter(function(){
    return this.innerHTML == 5;
}).html("good");

http://jsfiddle.net/kxkzU/5/

Also, your fiddle had .select as the className instead of just select.

Upvotes: 5

Related Questions