Dynamic HTML or DHTML is just a method of modifying style properties of an element by Javascript in response to a user action
for the purpose of making a web page or a part of it dynamic and interactive. The static part of a page such as this paragraph is
meant only for reading and does not respond to clicks or mouse overs, while the dynamic parts like the examples ahead respond
to mouse actions.
Making an element dynamic can measn changing its colors, moving it from one position to another or along a continuous path, changing
its content, making it visible or invisible, poping it up as message block. In order to do all this the lement has to have an id
attribute with a unique name. Remember this attribute in Core Attributes?
The code is amazingly simple. The above rectangles are nothing else but cells of a table with different bgcolor values, and
an onclick attribute. Here is code for the yellow cell.
The getElementById('menu') seeks the element whose id is 'menu', in fact our menu is contained in a DIV with id="menu".
Then accesses its style and assigns a value of 'yellow' to the background color. All spellings must be exactly as written here, if you
write 'backgroundcolor', with a small 'c', it doesn't work
Another example is to change the text properties when the mouse cursor is placed over it. Place your mouse over the following text.
mouse over
Several things happen to this text and the best way to explain it is to see the code. Note that two codes are required, one
for mouseover and the other for mouseout. The later are siply empty strings so that default values will apply.
Another point to observe is that instead of getElementById we used the word this. This is used when the action to
be taken is on the element for which the Javascript code is written.