I am trying to outputs an array of divs. My problem here is the quotes in the JS syntax.
}style = "style='background-color:#30C;'";
var add1 = 'add_to_collection(\''+k+'/'+i+'\');';
var add2 = 'change_color(\''+i+'/'+k+'\');';
divs_b = divs_b+"<div "+brk+" "+style+" onclick='"+add1+add2+" >"+k+"/"+i+"</div>\n";
}
}
document.getElementById('divs').innerHTML = divs_b;
document.getElementById('start').style.display = "none";
I later have the following out put in the source code:
The quotes will totally come out differently and the CSS markup totally disappears.
<div style="float:left;" class="divs" onclick="add_to_collection(" 2="" 1');change_color('1="" 2');="">2/1</div>
<div style="float:left;" class="divs" onclick="add_to_collection(" 3="" 1');change_color('1="" 3');="">3/1</div>
<div style="float:left;" class="divs" onclick="add_to_collection(" 4="" 1');change_color('1="" 4');="">4/1</div>
<div style="float:left;" class="divs" onclick="add_to_collection(" 5="" 1');change_color('1="" 5');="">5/1</div>
My preferred output would look like the following:
<div style="float:left;" class="divs" onclick="add_to_collection('2/1');change_color('1/2');" style="background-color:#30C;">2/1</div>
Here the whole function:
function build(){
/*var collect_border = document.getElementById('collect_border').innerHTML;
var collect_objects = document.getElementById('collect_objects').innerHTML;
var collect_enemies = document.getElementById('collect_enemies').innerHTML;*/
var collect_exit = document.getElementById('collect_exit').value;
/*var collect_start = document.getElementById('collect_start').value;
var collect_bonus = document.getElementById('collect_bonus').value;*/
/*collect_border = collect_border.split(';');
collect_objects = collect_objects.split(';');
collect_enemies = collect_enemies.split(';');*/
collect_exit = collect_exit;
/*collect_start = collect_start;
collect_bonus = collect_bonus.split(';');
*/
var x_val = document.getElementById('width').value;
var y_val = document.getElementById('height').value;
var divs_b = "";
var brk = "";
var style = "";
for(var i=1;i<=y_val;i++){
for(var k=1;k<=x_val;k++){
if((i>1)&&(k==1)){
brk = "style='clear:both;'";
}
else {
brk = "style='float:left;'";
}
// var addval = '"'+i+'"/"'+k+'"';
if(collect_exit!=""){
col_exit = collect_exit.split("/");
var col_exit_x = col_exit[0];
var col_exit_y = col_exit[1];
if((col_exit_x==i)&&(col_exit_y==k)){
}
}style = "style='background-color:#30C;'";
var add1 = 'add_to_collection(\''+k+'/'+i+'\');';
var add2 = 'change_color(\''+i+'/'+k+'\');';
divs_b = divs_b+"<div "+brk+" "+style+" onclick='"+add1+add2+" >"+k+"/"+i+"</div>\n";
}
}
document.getElementById('divs').innerHTML = divs_b;
document.getElementById('start').style.display = "none";
}