I'm new to JS, can't understand how to make this code work. I'm trying to overwrite the whole html source text.
var oldSource = document.documentElement.innerHTML;
alert(oldSource); //this works, it gets the whole html
document.write(Change(oldSource)); //doesn't work, writes undefined
function Change(source){
for (i = 0; i <= source.length; i++){
source[i] = "S"; // doesn't change the source[i]
}
}
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.min.js"></script>to the<head>of your html file imports the library. Once it's imported you can call.html()on a DOM element and pass in the new HTML you'd like it to contain. Note JQuery is used on over 55% of all web pages, according to wikipedia.Scharacters as you're iterating over a string, and if so, why ?Change??? Give your functions decent names so we can try to understand what you're trying to do.innerHTMLwasn't updating.