0

I am trying to form an array dynamically with the data present under ul li tag

<ul class="breadcrumb" style="background:none; margin-bottom:0px;">
   <li>Popcorn<i class="icon-angle-right"></i></li>
   <li>Bucket<i class="icon-angle-right"></i></li>
   <li>BucketT3<i></i></li>
</ul>

I have tried it this way

var arr = [];
$('.breadcrumb li').each(function() {
    var currentElement = $(this);

    var value = currentElement.val(); 
      arr.push(value);
});
alert(arr);

http://jsfiddle.net/40cka0wp/

The alert i am getting is 0,0,0 how i get the values as

Popcorn Bucket BucketT3

Thank you in advance .

2
  • look in the API docs...val() is for form controls Commented Nov 2, 2014 at 23:12
  • 1
    Exactly as what you have - except you need .text, not .val Commented Nov 2, 2014 at 23:13

2 Answers 2

4

You can use .map - and you want to get the text() of each li

var values = $('.breadcrumb li').map(function() {
    return $(this).text();
}).get();
Sign up to request clarification or add additional context in comments.

Comments

0

Just change

var value = currentElement.val();

to

var value = currentElement.text();

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.