admin 管理员组文章数量: 1086019
How can by jQuery get value inside tag b
?
<span>
<b>hi_1</b>
<b>hi_2</b>
<b>hi_3</b>
<b>hi_4</b>
<span>
I want this output with jQuery: hi_1, hi_2, hi_3, hi_4
Please give me example in jsfiddle.
How can by jQuery get value inside tag b
?
<span>
<b>hi_1</b>
<b>hi_2</b>
<b>hi_3</b>
<b>hi_4</b>
<span>
I want this output with jQuery: hi_1, hi_2, hi_3, hi_4
Please give me example in jsfiddle.
Share Improve this question asked Aug 31, 2011 at 14:19 Kate ThompsonKate Thompson 4412 gold badges7 silver badges13 bronze badges 1- -1 for not reading the documentation and trying something yourself – user142162 Commented Aug 31, 2011 at 14:21
3 Answers
Reset to default 3Are you looking for something like this?
http://jsfiddle/ZDYnq/
$(document).ready(function() {
var textArr = [];
$('span b').each(function() {
textArr.push($(this).text());
});
alert(textArr.join(', '));
});
To get the value inside a specific HTML tag in jQuery you can use the text function. This bined with a selector gets the output you're looking for
$('span b').each(function() {
console.log($(this).text());
});
JSFiddle
JSFiddle with mas
This is cool
var x = $("span b").map(function() {
return $(this).text();
}).toArray().join(", ");
Demo here
Discussed here
本文标签: javascriptget value of inside a tag with jQueryStack Overflow
版权声明:本文标题:javascript - get value of inside a tag with jQuery.? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744002479a2516699.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论