The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

This is fine, but...

I understand this is all done to show how the new DOM can work, but why would anybody go through this rigamarole just to change a DIV's style when they could do just the same by modifying a style sheet? Can anybody provide a real-world application of why someone would do this?

Re: This is fine, but...

Originally posted by dinomentia I understand this is all done to show how the new DOM can work, but why would anybody go through this rigamarole just to change a DIV's style when they could do just the same by modifying a style sheet? Can anybody provide a real-world application of why someone would do this?

Manipulation of the DOM allows you to change far more than just a style property on a <div>. In the examples listed in that article were also functions that change actual contents of an HTML element.

Furthermore, you can't really change a stylesheet on-the-fly. If you want the page to change (ie: DHTML) you have to use the DOM.

Re: Re: Re: This is fine, but...

Originally posted by jkd Why not use the DOM to change the stylesheet on the fly?
Ever heard of the DOM2 StyleSheets and DOM2 CSS implementations?

Pay very close attention to my language:
A stylesheet is a text file read by the client (browser). For obvious reasons, clients (browsers) can't alter files on the server. Therefore, no amount of DOM manipulation will change the stylesheet. Using DOM, you can modify the client's memory-resident interpretation of the style sheet, but make no mistake: when you return to that site, it will be the same stylesheet it was the first time, and you'll have to change it again.

Re: Re: This is fine, but...

Randem, I interpretted exactly what you said:

Originally posted by randem Furthermore, you can't really change a stylesheet on-the-fly.

on-the-fly in a web environment inherently implies client-side interaction, as only client-side scripting can change a document (in memory) without reloading it, hence "on-the-fly"; unless of course you also consider serving dynamically-generated pages (via some server side language) as "on-the-fly" as well (which is arguable and inconsistent usage of terms).