I need to grab the text value of a child div.
<div id='first'>
<div id='first_child'>A</div>
<div id='second_child'>B</div>
<div id='third_child'>C</div>
</div>
I am trying to grab the value B. I am currently trying this but it is not working,
var text_val = $('#first').next('#second_child').val();
You want to use
children()andtext()instead ofval(). Although, since what you are selecting has an id (and ids must be unique), you could also simply select based on the id without involving the container element at all.The
val()method only works on input elements, textareas, and selects — basically all form elements that contain data. To get the textual contents of a container, you need to usetext()(orhtml(), if you want the mark up as well).or