I'm doing a each function for all elements with a spesific class, but here it only fetches the last one, and not putting all of them into the JSON-array.
JS fiddle here: http://jsfiddle.net/MYGCM/1/
Here is the HTML:
<div id="324834" class="selected_pages">One</div>
<div id="436346" class="selected_pages">Two</div>
<div id="768653" class="selected_pages">Three</div>
Jquery
var pages = new Object();
var publish = [];
$('.selected_pages').each(function () {
pages.name = $(this).text();
pages.id = this.id;
publish.push({
Pages: pages
});
});
var json_pages = JSON.stringify(publish);
alert(json_pages)
Any input on this?