Reputation: 11
Currently, have functionality whereby mouseover will change the div to red upon placing the mouse over. I would like to change this to have an alert pop up instead, which displays the text held within the div.
I have tried calling a function to call the alert
<img onmouseover='getAlert(this)' class='calPicSmile' src= 'img/" + calImg + ".png' height= '20' width= '20'>
as well as
document.getElementsByClassName("calPicSmile").onmouseover = function() {getAlert()};
function getAlert(){
alert('test');
}
if (counter == day && month == curMonth && year == curYear) {
htmlContent += "<td class='dayNow alert' id='" + counter + monthIDName + "' onMouseOver='this.style.background=\"#FF0000\"; this.style.color=\"#FFFFFF\"' " + "onMouseOut='this.style.background=\"#FFFFFF\"; this.style.color=\"#FF0000\"'>" + counter + "<img class='calPicSmile' src= 'img/" + calImg + ".png' height= '20' width= '20'>" + "</td>";
} else {
htmlContent += "<td class='monthNow alert' id='" + counter + monthIDName + "' onMouseOver='this.style.background=\"#FF0000\"'" + " onMouseOut='this.style.background=\"#FFFFFF\"'>" + counter + "<img class='calPicSmile' src= 'img/" + calImg + ".png' height= '20' width= '20'>" + "</td>";
}
Upvotes: 0
Views: 13088
Reputation: 5941
Without you having to post full code, are you trying to achieve something like this?
function getAlert(image) {
alert('Here\'s an alert!')
}
<img onmouseover='getAlert(this)' class='calPicSmile' src='https://images-production.global.ssl.fastly.net/uploads/photos/file/117262/michae-scott-quotes-5.jpg?auto=compress&crop=top&fit=clip&h=500&q=55&w=698' height='100' width='140'>
Upvotes: 2
Reputation: 4067
<html>
<body>
<script>
function Alert(e){
alert(e.target.innerText);
};
</script>
<div onmouseover="Alert(event)">Hover Me</div>
</body>
</html>
Is this you want?
Upvotes: 3