So I am writing a code that displays an alert box whenever the mouse hovers over a piece of text in HTML. The problem that I have is it is not working and I am not sure why. I tried finding help online but none of them worked. I need something that doesn't use JQuery for this assignment. What I have tried is to use function when activated with the mouse over event handler but that also didn't work.
This is my code:
function mouseOver(){
showAlert();
}
function showAlert(){
alert("Alert!");
}
This is another method that I have tried:
function mouseOver(){
document.getElementById("text").alert("Alert!");
}
CodePudding user response:
Try this
function mouseOver(){
alert("Alert!");
}
CodePudding user response:
You can use this
document.getElementById("text").addEventListener("mouseover", function( event ) {
alert("Alert!");
}, false);
<p id="text">Hover Me</p>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>