Solved

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

Posted on 2013-05-22
6
289 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This article discusses how to create an extensible mechanism for linked drop downs.
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…

776 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