Reputation: 21
I m adding child divs of main div into array by id but couldn't get what is the problem.......? after adding into array i waant to send to ajax to write in csv
<!DOCTYPE html>
<html>
<body>
<p>Click the button to convert the array into a String.</p>
<div id='main'>
<div id='a'>
dab
</div>
<div id='b'>
nav
</div>
</div>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var array = $('#main id').map(function() {
return $(this).val();
}).get();
array.toString();
document.getElementById("demo").innerHTML = array;
}
</script>
</body>
</html>
Upvotes: 1
Views: 1881
Reputation: 67207
Try to use attribute selector
properly,
var array = $('#main [id]').map(function() {
return $(this).text();
}).get();
Also .val()
is a jquery function is specially for the elements which yields value
property when accessing it on a node object. So when you want to access the content inside a div
, you have to use .text()
Upvotes: 2