2

I am trying to show an alert box with the message "Let's have fun!" when the hover occurs. It has to use a jQuery script block that includes the ready event, and a jQuery statement to listen for the hover event in the main element. Then using JavaScript to display the alert box. The code below is what I have, BUT it doesn't display the alert mssg when I hover the to the hyperlink of "let me see".

I've researched online but doesn't get what is the mistake.

<head>
    <script
    src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js">
    </script>
    <script>
    $(document).ready(function(){
        $('#').hover(function(){
            alert("Lets have fun!");
        });
    });
    </script>
</head>
<main>
<p>Now Now Now <a href="#">Let me see</a></p>
</main>

3 Answers3

1

In jQuery, the "#" represents id's, like <a href="" id="#"></a>.

Try this, $("[href='#']") instead.

$("[href='#']").on('hover', function(){
   alert('Hello');
});
0

You can simply use a

CSS selector

. Hope this helps!

   $("a[href='#']").hover(function () {
        alert("Lets have fun!");
    });
HenryDev
  • 4,685
  • 5
  • 27
  • 64
0
$(document).ready(function() {
  $('* a[href="#"]').on('mouseover', function() { // For all elements <a> that have href="#"
    alert('worked!');
  });
});

If you want the effect "onmouseover"

Lucas Paz
  • 805
  • 7
  • 9