1

if i have the following:

<input type="text" id="something_txtYear" />

How do select this in JQuery using just the "txtYear" part??

Malcolm

5 Answers 5

6

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.

Sign up to request clarification or add additional context in comments.

Comments

1
$('[id$=txtYear]')

Comments

1

$('input[id*=txtYear]')

Comments

1

You can use the attribute endsWith selector

$('input[id$=txtYear]')

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.