jQuery - find a label in a string by its innerHTML and add an attribute


I have the following piece of code in my HTML file

        <!-- ......... -->

using jQuery I get

      var subHTML=$("select").html();

Can I find an option tag by its innerHTML in subHTML string, insert attribute "selected" and then put the edited string back into the select tag



I tried

  var strel=$(subHtml).find('option:contains("123")').attr('selected','selected');

but it adds only one option to the select tag.

This should work. (Not tested).

var to_replace = $("select").find('option:contains("The text i want to find")');
to_replace.attr("selected", "selected");
to_replace.text("The new text");