I have a rails application where I get the following response when I use jQuery get function. I have to get all div elements with id='users_belonging_to_project'.
As you can see there are multiple divs with same id. I want to get the whole html() for those ids.
As it is returned from response, I used $(data).find("div[id^='users_belonging_to_project']") which is not giving the array of divs.
<div id='i_1' class='clicked'>A</div>
<div id='users_belonging_to_project' class='demo-container'>
<div id='2' class='user_clicked'>
tm@gmail.com
</div>
</div>
<div id='i_2' class='clicked'>B</div>
<div id='users_belonging_to_project' class='demo-container'>
<div id='2' class='user_clicked'>
tm@gmail.com
</div>
</div>
<div id='i_3' class='clicked'>dsf</div>
<div id='users_belonging_to_project' class='demo-container'>
<div id='3' class='user_clicked'>
tm1@gmail.com
</div>
</div>
<div id='i_4' class='clicked'>fd</div>
<div id='users_belonging_to_project' class='demo-container'>
<div id='2' class='user_clicked'>
tm@gmail.com
</div>
<div id='3' class='user_clicked'>
tm1@gmail.com
</div>
</div>
The id of an element is supposed to be unique, thus
getElementByIdreturns one element and jQuery is itself not looking for more than one element with the same id. Change this from id-s to some other attribute and select by that attribute. You can use an HTML5 attribute likedata-identifieror some otherdata-*attribute that you like.