The linked duplicate explains you can only use an id once, but if you read my code, each id is unique. From the linked question:
Each id value must be used only once within a document. If more than one element has been assigned the same ID, queries that use that ID will only select the first matched element in the DOM. This behavior should not be relied on, however; a document with more than one element using the same ID is invalid.
This however is not what my code below is doing. Before being so quick on the close trigger, please read the question or at least provide a link to an answer that actually addresses my question.
Original post:
Can someone explain why when using the code below, in the console it lists each div as "1" and a separate line item such as:
1
1
1
1
instead of logging "4"
I am trying to count the number of divs with the id that matches. It is not inside of a .each
or anything
success: function (data) {
var n = jQuery('#name_' + cid ).length;
console.log(n)
}
This outputs a <div id=name_15>
with a number that changes and is unique