S
S
Sergey2015-09-24 16:26:00
JavaScript
Sergey, 2015-09-24 16:26:00

How to properly insert elements in JavaScript?

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Пример</title>
</head>
<body>
    <div class="test">Тест</div>
</body>
</html>

On jquery:
var opt = {
    'css' : '<style type="text/css">.test{color:red;}</style>',
    'html' : '<div>Привет мир</div>'
};
$(head).append(opt.css);
$(body).append(opt.html);

I need to rewrite this code without using jQuery.
For example, this does not suit me very well, because it will overwrite all elements and, as I understand it, they will reload
var head = document.getElementsByTagName('head')[0];
head.innerHTML += opt.css;

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question