I'm not quite sure if I am doing this right, as I am no jquery pro. But here are the facts: I need all the #box in my kontinent[i].content as html code appeded to the previous html in the #content div. This seems to work just fine at first, but when I look closely, only the first element (eg. "#box1" in europe.content is appended and I don't understand why.
Do I have to loop through the elements selected by kontinent[i].content?
Here is my code:
$(document).ready( function() {
var europa = {
content: $( '#box1,#box5,#box6,#box7,#box8,#box9,#box10,#box13,#box18,#box19,#box20,#box21,#box23,#box25,#box27,#box28,#box32,#box33,#box37' ),
name: "europa"
};
var usa1 = {
content: $( '#box38' ),
name: "usa1"
};
var usa2 = {
content: $( '#box3,#box17' ),
name: "usa2"
};
var afr = {
content: $( '#box29' ),
name: "afr"
};
var asi = {
content: $( '#box4,#box11,#box12,#box14,#box15,#box16,#box22,#box24,#box26,#box30,#box31,#box34,#box35,#box36' ),
name: "asi"
};
var aus = {
content: $( '#box2' ),
name: "aus"
};
var kontinent = [europa, usa1, usa2, afr, asi, aus];
var content = $('#content');
var precon = content.html();
var i = 0;
$('#world-weltkartelinks a').click( function( event ) {
event.preventDefault();
i = 0;
while ( i <= 5 ) {
if ($(this).attr('data-region') == kontinent[i].name) {
content.html(precon + kontinent[i].content.html());
};
i++;
};
});
});