jquery - Get value of all span elements within a ul -


i want value of span elements class 'pull-left' inside ul li tag. below tried code getting empty list. going wrong ?

    <html>     <head>         <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js">                                       </script>         <script>             var textarray = $('.order-review ul li h3').find('span.pull-left').map(function(){                 return $(this).text();             }).get();             console.log(textarray);         </script>     </head>     <body>          <div class="order-review">              <h2 class="color text-center">your </h2>              <ul class="order-summary"><li><h3><span class="pull-left">food</span><span class="pull-right color">×1</span></h3></li></ul>              <ul class="order-summary"><li><h3><span class="pull-left">food1</span><span class="pull-right color">×1</span></h3></li></ul>                                 </div>     </body>     </html> 

pretty common problem...

you need wrap functionality in jquery ready function.

your code should this:

$(function() {     var textarray = $('.order-review ul li h3').find('span.pull-left').map(function(){         return $(this).text();     }).get();     console.log(textarray); }); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -