Solved

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

Posted on 2013-05-22
6
292 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
Industry Leaders: 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
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…
Suggested Courses

710 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