Reputation: 441
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.
Upvotes: 1
Views: 12419
Reputation: 755577
To get the value inside a specific HTML tag in jQuery you can use the text function. This combined with a selector gets the output you're looking for
$('span b').each(function() {
console.log($(this).text());
});
Upvotes: 3
Reputation: 178421
This is cool
var x = $("span b").map(function() {
return $(this).text();
}).toArray().join(", ");
Upvotes: 0
Reputation: 69915
Are you looking for something like this?
$(document).ready(function() {
var textArr = [];
$('span b').each(function() {
textArr.push($(this).text());
});
alert(textArr.join(', '));
});
Upvotes: 3