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

javascript - get value of inside a tag with jQuery.? - Stack Overflow

programmeradmin2浏览0评论

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

3 Answers 3

Reset to default 3

Are 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

发布评论

评论列表(0)

  1. 暂无评论