Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Created June 15, 2013 04:15
Show Gist options
  • Save hanigamal/5786872 to your computer and use it in GitHub Desktop.
Save hanigamal/5786872 to your computer and use it in GitHub Desktop.
jQuery match a text attribute that does not exist
//You're trying to match a text attribute that does not exist. You cannot write:
$("#Select0 option[text='" + myText + "']").get(0).selected = true;
You can use filter() instead:
$("#Select0 option").filter(function() {
return $(this).text() == myText;
}).get(0).selected = true;
//Or, taking more advantage of the library:
$("#Select0 option").filter(function() {
return $(this).text() == myText;
}).first().prop("selected", true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment