How can you use the :contain() on an input field, e.g.
#inputfield contains a dynamic value of 5.938 and I want to use $("#inputfield:contains('5.938')").
But that won’t work, I’ve provided a demo at jsFiddle.
I don’t want to use if(element.val() == '5.938') because I need a provisional selector instead doing an if/else statement.
I also don’t mean by using [value=5.938] because the value will change.
Due to @Neal’s answer, you need to use some sort of conditional. A simple selector won’t work.
.filter()will suffice, however:That said, it looks like you’re using an ID selector, which can select at most one element, so
.filter()is overkill —if...elsereally makes the most sense in that case.