Get ID of the element I hover over with jQuery?

Viewed 89376

I have a bunch of elements that look like this:

<span class='tags' id='html'>html</span>
<span class='tags' id='php'>php</span>
<span class='tags' id='sql'>sql</span>

How would I get the name of the id of the one I hover over, so I could output something like "You're hovering over the html tag". (What I want to do isn't that arbitrary, but I do need to get the name of the tag the user hovers over in order to do it.)

4 Answers

Use this one:- 

    <!DOCTYPE html>
    <html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
        $("p").hover(function(){
        
            //if get onhover id
            alert("NOW GET ON HOVER ID NAME:--"+" "+this.id);
            
            //if get onhover class
            alert("NOW GET ON HOVER CLASS NAME:--"+" "+$(this).attr('class'));
            
            
        });
    });
    </script>
    </head>
    <body>

    <p class="getclass" id="get_class_id" >Hover the mouse</p>

    </body>
    </html>

Related