Created
June 15, 2013 04:15
-
-
Save hanigamal/5786872 to your computer and use it in GitHub Desktop.
jQuery match a text attribute that does not exist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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