I am new to jQuery and hope someone can help me with this and also provide a short explanation so that I can apply it for similar cases in the future.
I have a large HTML page that is built dynamically.
The page contains several tables with certain divs that are editable (contenteditable=true). These divs all have the class "editable".
Now I would like to create an array for all these divs that contains their id and their content (text).
So far I have the following which should create unique ids for these divs with an incrementing number but I am not sure on how to create the array for this. Also, just out of curiosity, is there a certain term how to call such arrays with two values per item ?
My jQuery:
$('#btnSave').on('click', function(){
var i = 0;
$(this).closest('form').find('div.editable').each(function(){
$(this).attr('id', 'ed' + i+1);
if( ($(this).text != '') && ($(this).text != ' ') ){
$(this).addClass('edited');
}
i++;
});
});
// my attempt for the array (perhaps the wrong approach):
var arrEdited = new Array();
$('div.edited').each(function(){
arrEdited.push($.trim($(this).text()));
});
Many thanks in advance, Mike
$(this).text, it should be$(this).text()