Answers for "creer un element html en javascript"

11

create element javascript with id

var btn = document.createElement('div'); 
btn.setAttribute("id", "div1");
Posted by: Guest on June-15-2020
1

Insertion d'éléments HTML avec JavaScript

function create(htmlStr) {
    var frag = document.createDocumentFragment(),
        temp = document.createElement('div');
    temp.innerHTML = htmlStr;
    while (temp.firstChild) {
        frag.appendChild(temp.firstChild);
    }
    return frag;
}

var fragment = create('<div>Hello!</div><p>...</p>');
// Vous pouvez utiliser des méthodes DOM natives pour insérer le fragment:
document.body.insertBefore(fragment, document.body.childNodes[0]);
Posted by: Guest on February-24-2020

Code answers related to "creer un element html en javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language