Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
If we add another element here--let me add a headline--you will see that that element gets added into the document structure. If I add a paragraph, that also gets added, and if I create an element like an emphasis tag inside my paragraph, that gets added as a children of this paragraph object. Now, if you do add a div with an ID then that ID becomes a way that you can target that particular element.
Now that I have targeted that div in that variable, I can use that variable and modify the innerHTML, which is the HTML inside the element, to be whatever I want. In my case, I want to use the request and then look for the responseText. Let's go ahead and save this, and I'll switch over to my browser, and I'll load up the page and you could see the document has loaded Hello World into just the ID for update. So let me go ahead and right-click and Inspect Element.
We could see the div with the ID of update is right here, and I have inserted the text Hello World from my external document into that div. So getElementById combined with innerHTML gives you a very quick way to update any element in your DOM as long as it has an ID. This is sort of like a laser that lets you target an individual element very quickly.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 105512 Viewers
56 Video lessons · 117171 Viewers
71 Video lessons · 86406 Viewers
131 Video lessons · 41306 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.