count div elements with the same id JQUERY

Give class name for div and paste the below code.. It will give the count.

var conveniancecount = $("div[class*='conveniancecount']").length;

Maybe this can be useful for you:

I've been making inner ajax calls wich may be the container starts wrapping inside one time and another in some cases. I resolve it with this:

jQuery("div[id='yourWrapper_1']").length

Try unwrapping it, because you shouldn't have repeated ID's on your DOM

http://api.jquery.com/unwrap/

Hope it helps you

Regards!


Having same id multiple times is not recommended by W3C. See what they say about it.

The id attribute specifies a unique id for an HTML element (the id attribute value must be unique within the HTML document). The id attribute can be used to point to a style in a style sheet. The id attribute can also be used by a JavaScript (via the HTML DOM) to make changes to the HTML element with the specific id.

Suggestion:

Use class name for all the divs you want to group and use this selector:

$('.myClassName')

See these references for more:

1. Why do Ids need to be unique

Tags:

Html

Css

Jquery