Skip to content Skip to sidebar Skip to footer

Using Multiple Id In Jquery

I made little jquery script for checking if input box value bigger than 5 .but I have 2 tag with an id and only one of them works.
<divid="register"><formid="register"><inputid="first"type="text" /><aclass="first" ></a><br /><inputid="second"type="text" /><aclass="second" ></a></form></div>

The jQuery selectors you're using:

$('a.first')
$('a.second')

Are looking for an <a> with a class. If you were trying to look for an <a> with an id, they would need to be as follows:

$('a#first')
$('a#second')

Solution 2:

change the ID of register , its not correct to have two identical ID's in the same page , after that everything should be working fine

cheers

Solution 3:

Agreed with not having duplicate id's. Easier to keep track of, and cleaner code. My two cents :), after having to refactor a chunk of code at work recently that had duplicate id's that failed to work in IE. Lesson learned!

Post a Comment for "Using Multiple Id In Jquery"