Solved

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

Posted on 2013-05-22
6
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

756 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