admin管理员组文章数量:1292244
I want to select the following value from the HTML file either by Jquery or Javascript.
Bank Transfer
, can some one suggest me how can i do.
<div class="color-me" id="txnDetails">
<div class="panel-apply-font-size">
<div class="row">
<div class="cols">
<dl class="entityDetails-field">
<dt>PaymentMethod</dt>
<dd>Bank Transfer</dd>
</dl>
</div> <!--end of cols-->
<div class="cols">
<dl class="entityDetails-field">
<dt>AccountNumber</dt>
<dd>34343</dd>
</dl>
</div> <!--end of cols-->
<div class="cols">
<dl class="entityDetails-field">
<dt>BankName</dt>
<dd>Bank Of America</dd>
</dl>
</div> <!--end of cols-->
</div><!--end of rows-->
</div><!--end of panel-->
</div><!--end of color me-->
I was doing like this:
$("#txnDetails dd").on(function(){
$(this)....
});
here I don't have any class-names nor ID tags given for DT
, DD
elements, how can I get to the first DD tag to pick it's text? I want the text of first DD tag that is value "Bank Transfer".
I want to select the following value from the HTML file either by Jquery or Javascript.
Bank Transfer
, can some one suggest me how can i do.
<div class="color-me" id="txnDetails">
<div class="panel-apply-font-size">
<div class="row">
<div class="cols">
<dl class="entityDetails-field">
<dt>PaymentMethod</dt>
<dd>Bank Transfer</dd>
</dl>
</div> <!--end of cols-->
<div class="cols">
<dl class="entityDetails-field">
<dt>AccountNumber</dt>
<dd>34343</dd>
</dl>
</div> <!--end of cols-->
<div class="cols">
<dl class="entityDetails-field">
<dt>BankName</dt>
<dd>Bank Of America</dd>
</dl>
</div> <!--end of cols-->
</div><!--end of rows-->
</div><!--end of panel-->
</div><!--end of color me-->
I was doing like this:
$("#txnDetails dd").on(function(){
$(this)....
});
here I don't have any class-names nor ID tags given for DT
, DD
elements, how can I get to the first DD tag to pick it's text? I want the text of first DD tag that is value "Bank Transfer".
-
try
$(#txnDetails dd:first).text()
– Tamil Selvan C Commented Jun 24, 2014 at 1:42 -
on
what? What's the user event you're interested in?click
,hover
? can you be just a bit more precise? Whave you googled or explored SO on "how to get first children element of-type?" or anything similar? – Roko C. Buljan Commented Jun 24, 2014 at 1:46 -
On a side note your HTML seems exessive, there is a lot of nesting going on there. Do you really need an entire
div
to apply the stylepanel-apply-font-size
? Are you aware you can apply more than one classto an element? E.g for your top div could be<div class="color-me panel-apply-font-size" id="txnDetails">
. Do you really need thecol
divs? You probably could remove those and just use thedl
s for your colums. – Jon P Commented Jun 24, 2014 at 2:01
4 Answers
Reset to default 4Use
$('#txnDetails dd:first').text()
or
$('#txnDetails').find('dd').first().text()
Try the :nth-child() selector:
$("dd:nth-child(1)").text();
You only need to know the position the element you are targeting is in.
Required Reading:
http://api.jquery./nth-child-selector/
You can use the following:
$("#txnDetails dd").first().text()
You should be able to get the values with:
$('#txnDetails dd:first-child').val();
本文标签: javascripthow to get value of dl tag HTML from jqueryStack Overflow
版权声明:本文标题:javascript - how to get value of dl tag HTML from jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741544129a2384493.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论