Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a new html element? [closed]

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

I tried to prototyping it like this: HTMLUnknownElement.prototype.style.backgroundColor = "red"; but it doesn't work.

Could you please help me, how to manage it?

Thanks in advance,

like image 472
Hard Rain Avatar asked Dec 19 '12 17:12

Hard Rain


1 Answers

How about createElement()?

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

edit

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>
like image 103
VisioN Avatar answered Sep 25 '22 00:09

VisioN