admin管理员组文章数量:1415645
<html>
<head></head>
<body>
<span class="mtb-price">
<label Class="mtb-ofr"><b class="lb1"></b>AAAAA</label></span>
<script>
var sku = document.getElementsByClassName("mtb-ofr").childNodes[1].nodeValue;
alert(sku);
</script>
</body>
</html>
How do i access childNode of having class name 'mtb-ofr' using document.getElementsByClassName() ? and what should be the alternative of document.getElementsByClassName() to obtain the same result ??
<html>
<head></head>
<body>
<span class="mtb-price">
<label Class="mtb-ofr"><b class="lb1"></b>AAAAA</label></span>
<script>
var sku = document.getElementsByClassName("mtb-ofr").childNodes[1].nodeValue;
alert(sku);
</script>
</body>
</html>
How do i access childNode of having class name 'mtb-ofr' using document.getElementsByClassName() ? and what should be the alternative of document.getElementsByClassName() to obtain the same result ??
Share Improve this question asked Jun 22, 2012 at 18:41 Pooja DesaiPooja Desai 2271 gold badge6 silver badges16 bronze badges 3-
2
document.getElementsByClassName("mtb-ofr")[0].childNodes
? or just.children
. – sachleen Commented Jun 22, 2012 at 18:45 - 2 getElementsByClassName returns an array, you need to select an item of the array before you can drill down any deeper – jackwanders Commented Jun 22, 2012 at 18:45
- Basically what i want is to replace AAAAA with some other text. – Pooja Desai Commented Jun 22, 2012 at 18:48
3 Answers
Reset to default 2to change the label's text:
document.getElementsByClassName("mtb-ofr")[0].childNodes[1].nodeValue = 'something';
getElementsByClassName
returns an array. You need to first get the element from the NodeList.
document.getElementsByClassName("mtb-ofr")[0].childNodes[1].nodeValue
Use jQuery !
$('label.mtb-ofr').children()
You're done !
And you can filter more by passing parameters to children().
http://api.jquery./children/
版权声明:本文标题:javascript - How do i access childNode of <label> using document.getElementsByClassName()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745242445a2649404.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论