Reputation: 5977
How to get 3.1 and 3.2 from following HTML using JQuery?
<div class="question3">
<div class="pure-u-1-2 questionNumber">
<p class="boldText">3.1 </p>
</div>
<div class="pure-u-1-2 questionNumber">
<p class="boldText">3.2 </p>
</div>
</div>
Tried JQuery:
$.map($('.questionNumber'), function (el) { alert(el.html) });
How to get question numbers dynamically for class question3 in JQuery?
Upvotes: 0
Views: 1237
Reputation: 382150
You can use
var arr = $('.questionNumber').map(function(){ return +$(this).text() }).get()
This will produce this array: [3.1, 3.2]
Note that your own code fails because you use html
instead of html()
.
Upvotes: 2