JavaScript Tutorial

Using getElementById, getElementsbyTagName and Dynamic Styling

By Shawn Olson

This page demonstrates how you can apply styles to various elements on a web page using Dynamic HTML (DHTML) techniques with JavaScript. Use the form (below right) to manipulate some of the styles that appear in the example content below.

Tips

Dynamically Style HTML Elements using JavaScript
Choose Elements to apply this to
Specific targets


Class Targets


Styles









Example Content

This is the first paragraph in the example div. This paragraph is not very interesting; however, you may be suprised to find out that despite its lack of interesting content... it is also pointless. In reality, it is just here to take up space and demonstrate a function.

This is the second paragraph in the example div. This paragraph is even less interesting than the first one. It does, however, have some interesting features. For example, the first two sentences in this paragraph were emphasized. Despite the emphasis, you may be suprised to find out that this paragraph is also pointless. In reality, it is just here to take up space and demonstrate a function just like the first paragraph.

This is the third and middle paragraph in the example div. If you haven't noticed by now, these parapgraphs have been a little less than interesting. In fact, they may make some of my old English teachers feel that they have failed atrociously.

This is the fourth and almost last paragraph in the example div. If you haven't noticed by now, these parapgraphs have been very boring. Sorry about that... I just didn't want to use the old lorem ipsum stuff.

This is the fifth and final paragraph in the example div. I actually feel sorry for you if you took the time to read all this. The whole point of this was to point out the use of dynamic formatting/styling with JavaScript.


More Resources

Here are some other resources and tools by Shawn Olson:

About Shawn Olson

Shawn Olson is a freelance journalist, web programmer and photographer. You can find more of his work, including many free tutorials and resources, at www.shawnolson.net.

Copyright © 2009 by Shawn Olson. All Rights Reserved.