Reputation: 12874
if i have the following:
<input type="text" id="something_txtYear" />
How do select this in JQuery using just the "txtYear" part??
Malcolm
Upvotes: 1
Views: 353
Reputation: 914
Very important. You must have quotes around the value for jQuery 1.4.4 and above. This is how the selector should look now:
This does NOT work in jQuery 1.4.4
$('[id=txtYear]')
This does work for jQuery 1.4.4 and above:
$('[id="txtYear"]')
We had to update all of our code when we upgraded. This link gives a find and replace regular expression on how to fix this. http://nickjohnson.com/b/jquery-upgrade-how-to-fix-attribute-value-selector-errors
Upvotes: 0
Reputation: 212
Either $('[id$=txtYear]')
to match only at the end of the id or $('[id*=txtYear]')
to match anywhere in the id.
You'll want to look at: http://docs.jquery.com/Selectors , scroll down to the section on Attribute Filters.
Upvotes: 6
Reputation: 827992
You can use the attribute endsWith selector
$('input[id$=txtYear]')
Upvotes: 1