Reputation: 2062
The html code is as follows:
<div id="customer-projects">
<h3 class="lead"> Projects </h3>
<ul class="project-list">
.
.
</ul>
.
.
<ul class="project-list">
.
.
</ul>
<div>
Is there any particular reason why $('#customer-projects .project-list:nth-child(1)').html()
returns 'undefined' and not the contents of the first ul.
Upvotes: 1
Views: 927
Reputation: 40639
Use eq() like
$('#customer-projects .project-list:eq(0)').html(); //indexing starts from 0
Upvotes: 1
Reputation: 157334
Modify your selector like this, cuz the issue is, you are using nth-child(1)
which will match h3
element and not the ul.project-list
, so it will return undefined
, use nth-of-type(1)
with element.class
selector.
console.log($('#customer-projects ul.project-list:nth-of-type(1)').html());
Upvotes: 0