It somewhat depends on the browser. But in general, yes, you can do that. However, in your example, you are missing a leading # or . - presumable a # as it looks like an ID. Of course, you will have to use the dev tools in your browser to find a suitable selector.
Then when you send some text to the node, also set msg.className to "on" or "off".
You can do that based on the contents of msg.payload or a context variable as you wish, using a Function or Change node.