Speaking of yesterday’s post, it had the following problems:
1. It could not easily be embedded into an existing page.
2. It could not be placed wherever we wanted it to be nor it could be aligned or styled easily.
3. Rather than updating the same number to countdown it showed a series of numbers as countdown proceeded.
getElementById(). This is
help of their IDs (which is unique).
For example we can access the HTML entity and its values etc. with the ID
The HTML object may be defined like below:
<p id="one">some text</p>
OK, how can this be used to solve our problems, let’s see.
As we know, the HTML entities such as
etc. can be placed anywhere very easily. They can also be styled and aligned
perfectly. So if we could print the timer in one of these, it’d be the
most efficient technique. How? Using
The body of tags such as
<p>, <div> or <span>
e.g.: If we execute the following code:
it’d be same as having the following HTML tag:
This way two of our problems have been solved. What about the third one? It too has been solved, if you look closely.
For example when you write:
<p> would be displayed as having the text “Second”.
OK, below is the completed code:
It depends on what you intend regarding which tag you should use to place to
timer. If you want it to be inline with some text use
<p> would make it to be in a different paragraph.
So in this post we saw a very powerful method
which can be used to access HTML objects and manipulate them. Check back for