whiteletters in blankpapers whiteletters in blankpapers - 11 months ago 62
HTML Question

Get id of div in nested HTML elements using jquery

How can I get, using jquery, the

of the first div with class:
(367), in the following HTML code:

<div id="own-posts">
<span class="title">Me</span>
<div class="posts_container">
<div class="post"></div>

<div id="367" class="post"></div>
<div id="365" class="post"></div>
<div id="345" class="post"></div>
<div id="343" class="post"></div>



Among the solutions I tried:



The first .post element doesn't have an ID, so I guess you mean the first .post element that actually has an ID attribute :

var id = $('#own-posts .post[id]:first').prop('id');