0

I have a pair of values. I don't want a <key, value> pair. I want a <value,value> pair.

I have created a select tag. and its options are the pairs.

<option value="value1" >value2</option>

The code below selects the options that have value=i.

options = $("#myselect option[value='"+i+"']");

I want to select the option that value=val1 and text = val2.

Any other idea?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Habib Zare
  • 1,206
  • 8
  • 17
  • possible duplicate of [jquery find element by text](http://stackoverflow.com/questions/7321896/jquery-find-element-by-text) – Felix Kling Apr 29 '13 at 10:07

2 Answers2

1

You can use contains to further filter the selection:

options = $("#myselect option[value="+i+"]:contains('value"+j+"')");
Joseph
  • 117,725
  • 30
  • 181
  • 234
  • that _make up your mind_ comment was epic. May be because of invalid formatting not displaying the ``? lol :D – Ejaz Apr 29 '13 at 10:12
0

You could use jQuery's filter() for this

        var i = 1;
        var options = $("#myselect option[value='value" + i + "']").filter(function(){
           return $(this).text() == 'value'+(i+1)
        });
        console.log(options);

HTML

  <select id="myselect">
     <option value="value1">value1</option>
     <option value="value1">value2</option>
     <option value="value1">value3</option>
  </select>

selects <option value="value1">value2</option>

Ejaz
  • 8,719
  • 3
  • 34
  • 49