admin管理员组文章数量:1356883
I need to read the value of particular label inside the div tag using jQuery. Below is the HTML structure.
<div id="myDiv">
<label id="greenLabel">Hello</label>
<label id="redLabel">There you go!</label>
</div>
Can anyone help me to find the inner text of "redLabel" ?
I need to read the value of particular label inside the div tag using jQuery. Below is the HTML structure.
<div id="myDiv">
<label id="greenLabel">Hello</label>
<label id="redLabel">There you go!</label>
</div>
Can anyone help me to find the inner text of "redLabel" ?
Share Improve this question asked Nov 22, 2013 at 13:42 Dhaval PanchalDhaval Panchal 6124 gold badges12 silver badges32 bronze badges 1-
Maybe
$('#redLabel').html()
? – Florent Commented Nov 22, 2013 at 13:43
2 Answers
Reset to default 4Try # id-selector
$('#redLabel').text();
or
$('#redLabel').html();
$('#redLabel')
-->refers to element with id
redLabel
$('#redLabel').text();
--> get text of element with id
redLabel
$('#redLabel').text('value');
--> set text of element with id
redLabel
.text()
.html()
ID
must be unique. Use classes
for multiple items or refer to a group
Read Two HTML elements with same id attribute: How bad is it really?
try this
$("#myDiv #redLabel").text();
//go to div then label
// or can try if in label there is no element
$("#myDiv #redLabel").html();
you can also use $("#redLabel")
at the place of $("#myDiv #redLabel")
see also What is the difference between jQuery: text() and html() ?
本文标签: javascriptHow to find particular label value inside div tag using jQueryStack Overflow
版权声明:本文标题:javascript - How to find particular label value inside div tag using jQuery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743998054a2573352.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论