Let’s get started.
Manipulating HTML Elements
At some point during your programming experience, whether it be with HTML or with CSS, I am sure you have come across the
id attribute. This attribute is going to be your new best friend. By giving an HTML Element and
The first manipulation statement we will learn is
document.getElementById(id). By attaching
.innerHTML to the end of this statement, we can modify the HTML of an Element. Let’s check out an example and then break it down.
So what happened? Well, using the document.getElementById() statement, we were able to locate the Element with the
id of test and modify its value with .innerHTML! So in essence, the first part of the statement is locating the HTML Element, the second part is telling what part of the Element to edit, and the final part is telling the value to change it too! Neat huh?
Before we go any further, I want to explain what a string is. A string is a group of characters enclosed in quotations marks. The characters can be literally anything from letters, numbers, symbols, spaces and can be of any combination of them all and can vary between one character to an infinite number of characters. So in short a string can be a letter, a word, or a sentence.
document.write() statement. For this statement, you will put the output in between the parentheses. The output can be a text string, a variable, or a function. Let’s look at all three.
In this particular example we didn’t include any line breaks. Because of this, all the output is one right after another. We address this in the next section.
So we’re outputting some data, however it’s not looking too good clumped together like that. What we need is special characters. Special Characters serve a couple of functions. For example, what if you want to output the string:
Wikiprogramming is the "bomb"
Wikiprogramming is the \"bomb\"
\" to create a quotation, you can use
\n to skip to the next line. Let’s take the example in the previous section and apply some special characters to it.
Don’t worry too much about the syntax right now. We will cover what happened in Lesson 4 on Operators. The important thing is to recognize special characters and the purpose they serve.
List of Special Characters
document.write()but it’s not recommended
- Special Characters can be used to manipulate the data output