How to get an H1 text inside a div through an omouseover event and innerHTML property

Scene

New Member
I'm trying to write the content of my H1 inside a div when I put the mouse over the H1, but only get [Object HTMLHeadingElement], not the text itself. I'm a total beginner and I'm trying it with the innerHTML property. Thank you all!\[code\]HTML code:<h1 id="phrase" onmouseover="writeInDiv2()">Hi all</h1>JavaScript code:var text = document.getElementById("phrase");function writeInDiv2(){ if(div2.style.display != "none"){ div2.innerHTML = text; }}\[/code\]
 
Back
Top