Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get a specific child divs value from parent using jquery

I know this question is so familiar in stackoverflow, but still I can't find my solution. I want to get my child div's value when I click the parent div, but my current code gives me "undefined". My html is given below:

<div class="main">
  <div class="testId">
    1
  </div>
  <div class="testName">
    test
  </div>
  <div class="testDob">
    10/10/10
  </div>

</div> 

and my script is given below

var id = $(this).child(".testId").innerHTML;

any thoughts?

like image 354
Optimus Avatar asked Feb 03 '26 17:02

Optimus


1 Answers

Try using find():

var id = $(this).find(".testId").text();
like image 134
Brian Phillips Avatar answered Feb 06 '26 05:02

Brian Phillips