Text Manipulation - JS - BasicJS
Basic Text Manipulation using js and html
Text Manipulation - JS - BasicJS
Welcome to Basic Javascript 101 (BJS), by now you maybe wonder how all those websites you've been on show alerts,confirmation prompts and even how they manipulate text on a html website like its nothing.
Well you're at the right place :D
Okay, lets say you have a basic website that you've created and now you want to change the default "Hello World!" text to "The world wide web!". How exactly should we do this?
Well Hector remmembers that javascript allows us to get the first element that has a specific id using the following code
document.getElementById()
Well if Hector wants to use this way to change the text he needs to assign an id to the <h1>
tag. So Hector needs to add a id attribute to the heading tag, thats great.
Hector does this by adding a id attribute, and gives it an id value "bello"
<h1 id="bello">Hello World!</h1>
now he goes to the javascript file to automatically change the text value to "The world wide web", cool. He types in the following code
document.getElementById('bello').innerHTML = "The world wide web"
When he refreshes the output, the heading tag automatically changes to "The world wide web"
End of Part 1 :D