Reputation: 409
I have an li
element which looks like this:
<li><input type="radio" name="test" value="2" />Some text here</li>
How would I retrieve the text "Some text here" using JQuery? I was trying to use the children methods but I'm assuming that li
element only has one child as the whole thing is contained within the same li
.
Any help would be appreciated. Thank you!
Upvotes: 0
Views: 267
Reputation: 55
You assign an id for li
and you access via jQuery by id
.
HTML:
<li id="list"><input type="radio" name="test" value="2" />Some text here</li>
jQuery:
$('# list').Html()
Upvotes: 1
Reputation: 20740
Simply use just text()
method like following.
var text = $('li').text();
console.log(text);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><input type="radio" name="test" value="2" />Some text here</li>
Upvotes: 2