-1

How to select element with class MyClass and value MyValue, but without using each? I tried something like:

$(".MyClass").find("[value='MyValue']")
$(".MyClass[value='MyValue']")

This is example: http://jsfiddle.net/HQaG5/ It works if i use hard coded value for select element.

user1610362
  • 637
  • 2
  • 9
  • 26

4 Answers4

1

You want :contains() :

$( ".MyClass:contains('MyValue')" )
Anthony
  • 36,459
  • 25
  • 97
  • 163
0

Take a look here: jquery find element by text

You can use the :contains selector to find elements containing text.

But if you want to match an exact string then .filter is the better option

Community
  • 1
  • 1
andrew
  • 9,313
  • 7
  • 30
  • 61
0

If the element is an input and you want to search after property value you can use .filter()

$('.MyClass').filter(function(){
       return this.value=="MyValue";
});

DEMO

Anton
  • 32,245
  • 5
  • 44
  • 54
0

If you are looking to get the select box element that has the specified value selected (which seems to be the case based on your fiddle), then you can use this…

$(".MyClass option:selected[value='MyValue']").parent()

DEMO

However, I would question why you want to do this, as it seems kind of backwards.

Patrick Q
  • 6,373
  • 2
  • 25
  • 34