View Single Post
Old 02-15-2013, 07:18 AM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
id means "identity". What would you think if someone told you that you share your identity with others? You'd say: "No way, my identity is unique". And the same is true also for Javascript.

Bottom line: You should not use the same id attribute value on more than one element on the same page.

Workaround: Prepend a unique String to the numeric identifier, like "article_101" and "cell_101". Then you can extract the numeric part using
Code:
var numID = Number($(this).attr('id').match(/(\d+)/)[1]);
devnull69 is offline   Reply With Quote