<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <div id="title">DOM</div> <script> document.getElementById("title").classList.add("h5"); var h1 = document.createElement("h1"); h1.innerHTML = "hellow"; h1.className = "h1"; document.getElementById("title").appendChild(h1); if (document.getElementById("title").contains(h1)) { alert("yes") } </script> </body> </html>