javascript ,jquery, html
map multiple div elements into array
map multiple div elements into array
The
.val()
method is primarily used to get the values of form elements such as input, select and textarea. You need to use text()
method for this, as text()
string containing the combined text of matched elements.
Using
.val()
on span
element:
Using
.text()
on span
element:
Also call them individually for each element like this:
let arr = block.find('.contact').map(function() {
let type = $(this).find('.type').text().trim();;
let number = $(this).find('.number').text().trim();;
return { type, number};
}).get();
This will return you array of objects, where each object has text content of
type
& number
class elements.
DEMO:
Aucun commentaire