最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to find particular label value inside div tag using jQuery - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 4

Try # 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() ?

发布评论

评论列表(0)

  1. 暂无评论