Solved

In Javascript, how to get the current id of the div where mouse pointer is?

Posted on 2013-05-22
6
287 Views
Last Modified: 2013-06-17
How to get the id of the div on which the mouse is currently pointing?
0
Comment
Question by:sam_net
6 Comments
 
LVL 17

Assisted Solution

by:sonawanekiran
sonawanekiran earned 100 total points
ID: 39189904
Like this

<div id="the-id" onmouseover="getID(this);">some text</div>

<script>
   
    function getID(obj)
    {
        alert(obj.id);
    }
</script>

Test page : http://jsfiddle.net/eyhsm/
0
 
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 100 total points
ID: 39189992
<script>
   
    function getID(obj)
    {
var lastID = null;

var hMouseover = function (e) {
    var target = e.target || e.srcElement;
    lastID = target.id;
};

if (document.addEventListener) {
    document.addEventListener('mouseover', hMouseover, false);
}
else {
    document.attachEvent('onmouseover', hMouseover);
}
</script>
0
 
LVL 4

Accepted Solution

by:
mohammad827 earned 100 total points
ID: 39190006
<script language="JavaScript">
document.onmousemove = getMouseXY;
function getMouseXY(e) {

  alert(e.srcElement.id);
  return false;
}

</script>
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Assisted Solution

by:sam_net
sam_net earned 0 total points
ID: 39240840
Thanks.
0
 

Author Comment

by:sam_net
ID: 39240850
Working fine as expected
0
 

Author Closing Comment

by:sam_net
ID: 39252555
Working fine.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now