Server Side JS to modify HTML element attributes


(Nic Hubbard) #1

We use server side js quite a lot and it works great. However, this is the first time I am wanting to modify the DOM and edit an HTML element’s attributes.

Using normal javascript does not seem to do the trick. Is this something that ssjs cannot do?


(David Schoen) #2

SSJS is not able to see anything not directly injected in to the script tag, it can’t see the DOM as that’s a client side concept.


(Nic Hubbard) #3

Got it.

What I am using is a Remote Content asset to bring in a table. I need to remove some classes from it, but using javascript will give a delay and it will flash from ugly design to our new design.

Is there any other method of modifying the contents of the Remote Content before it is rendered?


(David Schoen) #4

I think a lot of people would use a REST Resource to do that now - it can run JS over the body before returning it meaning you could run custom code over it there.

There’s still no native DOM in that environment but you might be able to load something like jsdom or cheerio to give a familiar environment.

I’ll ask around as well.