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
Post a Comment