javascript - I am not able to append a for loop to a div tag in my HTML body. Any ideas? -
this code... not sure wrong.
i trying append while loop html in div tag #putthetreeinhere
.
please help.
function loop () { var index = 1; var row = "<font color=green><b>^</b></font>"; var newrow= row; while ( index <= 10 ) { document.write( "<center>"+newrow+"</center><br>" ); newrow = newrow + row; index += 1; } } function displaytree () { $( "#putthetreeinhere" ).append( loop() ) } $(document).ready(function () { displaytree(); });
see http://jsfiddle.net/alemarch/3k0x3c4l/1/ have change font tag span , centered text in div css #putthetreeinhere{ text-align: center;}
in loop function dont use document.write...
function loop () { var index = 1; var row = '<span style="color:green; font-weight:bold;">^</b></span>'; var html = ""; var newrow= row; while ( index <= 10 ) { html += newrow+"<br>" ; newrow = newrow + row; index += 1; } return html }
Comments
Post a Comment