How to create a new html element?

I tried to create a new HTML element called a test: <test>some text</test>

I tried to prototype it as follows: HTMLUnknownElement.prototype.style.backgroundColor = "red"; but it does not work.

Could you help me how to handle this?

Thanks in advance,

+4
source share
2 answers

There really is no reason for this.

If you want to create an element with a red background, you must use the existing element and assign it a CSS class that has a red background (for example, <span class="test"> ).

+5
source

How about createElement() ?

 var el = document.createElement("test"); el.style.backgroundColor = "red"; document.body.appendChild(el); 

change

If we start with:

 <html> <head></head> <body> </body> </html> 

The result will be:

 <html> <head></head> <body> <test style="background-color:red"></test> </body> </html> 
+9
source

All Articles