简体   繁体   中英

What is the DOM method to move the mouse over an element?

My question is very simple, I want to automate a process where I need to hover over a specific element first, and then click the second element which replaces the first one after hover. So what would be the dom method to use to make mouse pointer hover over that first element with plain javascript?

I guess you could use the JavaScript MouseOver event. Maybe have some sample code you want to use?

<p id="p" class="p" onmouseover="changElement()">Sample Code</p>
<script>
var el = document.querySelector('p');

function changeElement(){
var newEl = document.createElement('p');
newEl.innerHTML = '<b>Hello World!</b>';
el.parentNode.replaceChild(newEl, el);
}

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM