Hey guys,
My array is printing it’s values on page when:
document.write(unsorted[i]+"<br/>");
but not when trying to put it in a div referring the element by jquery
$("#no1").write(unsorted[i]+"<br/>");
Here’s my code:
$(function(){
var unsorted = new Array();
function randomNumber(x,y) { //gives a random number
return Math.floor((Math.abs(y - x) + 1) * Math.random()) + Math.min(x, y);
}
for(i=0; i<=33; i++){
unsorted[i]=randomNumber(0,33); //populates the array with random numbers
$("#no1").write(unsorted[i]+"<br/>"); //#no1 is a div
}
});
Jquery library is tested and works fine whatever is it’s my code!
Any suggestions why my approach is wrong appreciate any help
10x
You can only use the
document.writemethod when the page is loading, you can’t write to elements that already exist.Put the content together, and use the
htmlmethod in the jQuery library to put the content in the div: