Does jQuery('#id').length always return 1? -


i having trouble figuring out why .length seems return 1 when counting elements having same id in page. know there should elements unique html id's in html document, in project working on, user may inadvertently add duplicates.

so, normal behaviour jquery return 1 when counting elements id's?

<div id="1">foo</div> <div id="1">foo</div>  jquery(function(){    alert(jquery('#1').length); // returns 1 }); 

i have built example here: http://jsfiddle.net/esnzx/

thanks help

returns 0 or 1. multiple elements same id not valid.

it's not jquery or javascript restriction html one. check 7.5.2 element identifiers: id , class attributes official word that.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -