0

In HTML below, I want to retrieve the value of the all <b> tags using JavaScript or jQuery

<html>
   <head>
</head>
<body>        

 <span id=":zz" class="adl">

                   <b>2</b> 
                   <b>of </b>

                   <b>143 </b>

           </span>

<body>
</html>

Can I retrieve all <b> tag values using class name in jQuery or JavaScript?

4
  • what is the desired output format Commented Feb 24, 2014 at 10:34
  • $('.adl b') to access the values Commented Feb 24, 2014 at 10:35
  • @user3141775 Can you correct your span id first? Commented Feb 24, 2014 at 10:42
  • this is my auto generated id for this class. so i can't...would u tell me whats is worng in this id Commented Feb 24, 2014 at 11:06

3 Answers 3

3

You can place the values in to an array using $.map():

var values = $('b').map(function () {
    return $(this).text();
}).get();
console.log(values); // = ["2", "of ", "143 "] 

Example fiddle

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. Was in the process of creating a fiddle ;)
1
console.log($('span.adl').find('b').text());

Comments

1

You do not need even need classname to do that.just use:

$('.adl b').each(function(){
    alert($(this).html());
 })

1 Comment

Including span css class can match with the question header.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.