473,396 Members | 1,997 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Identify the source ID on mouse over

I have the following code:

<li onMouseOver='myid = (typeof event.target != "undefined")?
event.target:event.srcElement.id' id=li15>

I'm trying to assign the value of the element's id to the variable 'myid'
whenever the mouse goes over this element. But myid remains undefined. What
am I doing wrong? Is there a better way to write this code?

Thank you.

Jack
Sep 26 '05 #1
7 7822
ASM
Jack Hagouel a écrit :
I have the following code:

<li onMouseOver='myid = (typeof event.target != "undefined")?
event.target:event.srcElement.id' id=li15>

I'm trying to assign the value of the element's id to the variable 'myid'
whenever the mouse goes over this element. But myid remains undefined. What
am I doing wrong? Is there a better way to write this code?


<li id="lil5"
onmouseover="myid = this.id"
onmouseout="alert('myid = '+myid)">
foo
</li>

perhaps ? event.this.srcElement.id ?
or ? this.event.srcElement.id ?
--
Stephane Moriaux et son [moins] vieux Mac
Sep 26 '05 #2
ASM
Jack Hagouel a écrit :
I have the following code:

<li onMouseOver='myid = (typeof event.target != "undefined")?
event.target:event.srcElement.id' id=li15>

I'm trying to assign the value of the element's id to the variable 'myid'
whenever the mouse goes over this element. But myid remains undefined. What
am I doing wrong? Is there a better way to write this code?


Tell it when you use IE slang,
"There is no public standard that applies to this property."
they say here :
http://msdn.microsoft.com/workshop/a...srcelement.asp

<li id="li_15"
onMouseOver="myid = (typeof event.target != 'undefined')?
event.srcElement.id : event.target"
onMouseOut="alert('myid = '+myid)"> foo </li>

seems to work, don't ask me why ...

--
Stephane Moriaux et son [moins] vieux Mac
Sep 26 '05 #3
ASM <st*********************@wanadoo.fr.invalid> wrote in
news:43**********************@news.wanadoo.fr:
Jack Hagouel a écrit :
I have the following code:

<li onMouseOver='myid = (typeof event.target != "undefined")?
event.target:event.srcElement.id' id=li15>

I'm trying to assign the value of the element's id to the variable
'myid' whenever the mouse goes over this element. But myid remains
undefined. What am I doing wrong? Is there a better way to write this
code?


<li id="lil5"
onmouseover="myid = this.id"
onmouseout="alert('myid = '+myid)">
foo
</li>

perhaps ? event.this.srcElement.id ?
or ? this.event.srcElement.id ?


Stephane,

Thank you, the simple 'this.id' seems to get the id; the problem though
is that there are multiple objects overlapping each other and it gets
the id of the topmost object whereas I need the id of the one on the
bottom (gets the id of the whole list, I need the id of the list item).
Any ideas?

Jack
Sep 26 '05 #4
ASM
Jack Hagouel a écrit :

Stephane,

Thank you, the simple 'this.id' seems to get the id; the problem though
is that there are multiple objects overlapping each other and it gets
the id of the topmost object whereas I need the id of the one on the
bottom (gets the id of the whole list, I need the id of the list item).
Any ideas?


id of all list ?
how many floors ?

<ul id="got_it">
<li>one</li>
<ul>
<li>two</li>
<ul>
<li onmouseover="trick=parent.node.parentNode.parentNo de.id"
onmouseout="alert('trick = '+trick);">three</li>
</ul>
</ul>
</ul>
If you haven't see my other answer which only can work with IE alone
you can also search about 'propagation' and 'stopPropagation'

--
Stephane Moriaux et son [moins] vieux Mac
Sep 26 '05 #5
ASM
ASM a écrit :
correction :

<ul id="got_it">
<li>one</li>
<ul>
<li onmouseover="trick=parentNode.parentNode.id"
onmouseout="alert('trick = '+trick);">two</li>
<ul>
<li onmouseover="trick=parentNode.parentNode.parentNod e.id"
onmouseout="alert('trick = '+trick);">three</li>
</ul>
</ul>
</ul>
<style type="text/css">
li { background:#ff9;border:1px solid red; width: 6em; }
</style>

--
Stephane Moriaux et son [moins] vieux Mac
Sep 26 '05 #6
ASM wrote:
Jack Hagouel a écrit :

Stephane,

Thank you, the simple 'this.id' seems to get the id; the problem
though is that there are multiple objects overlapping each other and
it gets the id of the topmost object whereas I need the id of the one
on the bottom (gets the id of the whole list, I need the id of the
list item). Any ideas?

id of all list ?
how many floors ?

<ul id="got_it">
<li>one</li>
<ul>
<li>two</li>
<ul>
<li onmouseover="trick=parent.node.parentNode.parentNo de.id"
onmouseout="alert('trick = '+trick);">three</li>
</ul>
</ul>
</ul>
If you haven't see my other answer which only can work with IE alone
you can also search about 'propagation' and 'stopPropagation'


In your code (not quoted), 'this' always refers to the element that
fired the onmouseover. There is no need to use event.srcElement (IE) or
event.target (Mozilla) unless you want to get the element that triggered
a bubbling event.

Bubbling can be useful, the onmouseover could be on the parent ul only,
then use target/srcElement to find whatever it was that the mouse was
over (see below).

stopPropagation etc. is only required to prevent bubbling to an event
attached to an element higher up the DOM tree. It seems that the OP's
need is to get down to an element that has a lower z-index that the one
that triggered the event. I don't know if that is possible without
searching down the DOM for a specific element.

<script type="text/javascript">

var myId;

function showID(e)
{
var e = e || window.event;
var tgt = e.target || e.srcElement;
if (tgt.id) myId = tgt.id;

// just for show
document.getElementById('msg').innerHTML = myId;

}

</script>

<ul id="ulList" onmouseover="showID(event);">
<li id="li1">li 1
<li id="li2">li 2
<li id="li3">li 3
</ul>

<div id="msg"></div>

--
Rob
Sep 26 '05 #7
ASM
RobG a écrit :
ASM wrote:
[ a script filled up with errors ]

[...]

Really, it's allways a pleasure to see your scripts
so short, clear and efficient.

But I have some difficulties to follow this concept of target
I did try with :

<div id="ulList" onmouseover="showID(event);">
<p id="li1">li 1
<p id="li2">li 2
<p id="li3">li 3
</div>

and it works too

So I can have an alone roll-over function for
a complete div insteed to have to copy it from links to links ?

Tremendous ! it works here too (2nd underfloor 'a') :

<style>
a { display:block;width: 100%;background:yellow}
</style>
<div id="ulList" onmouseover="showID(event);">
<p><a id="li1">li 1</a>
<p><a id="li2">li 2</a>
<p><a id="li3">li 3</a>
</div>

No deep end with this targeting ?
<script type="text/javascript">

var myId;

function showID(e)
{
var e = e || window.event;
var tgt = e.target || e.srcElement;
if (tgt.id) myId = tgt.id;

// just for show
document.getElementById('msg').innerHTML = myId;

}

</script>

<ul id="ulList" onmouseover="showID(event);">
<li id="li1">li 1
<li id="li2">li 2
<li id="li3">li 3
</ul>

<div id="msg"></div>

--
Stephane Moriaux et son [moins] vieux Mac
Sep 27 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John Champaign | last post by:
Hi all, I'm working on an educational applet for a child with special needs. He's got a bit of a trick to make my life more difficult... To interact with the applet he needs to click on...
1
by: Gina | last post by:
I need to add the cell generation to a templated program. I am using graphics magician, but my problem is with the math. I cannot figure out my cell generations. I do know that I need two...
7
by: fernandoronci | last post by:
Hi, I've been given the task of mantaining and fixing a website which I didn't design. I'm using Internet Explorer 5.5 and 6.x. Specifically, the problem is that navigation menues (written in...
3
by: Logan Mckinley | last post by:
I need to be able to detect mouse movement even when it is not over my application. I can get the mouse cords using MousePosition but I am not sure if there is an event that hits my program when...
8
by: NeoAsimov | last post by:
Hello, There is what I want to do. I worked on the problem since 6 hours but I had a problem (probably stupid) and I dont know how to resolve it. I need to have an Mouse Event Click when...
1
by: TheunsP | last post by:
Problem : I want to click the mouse from source code. I move my mouse from source code over another application's display. I now want the mouse to click on the new cursorposition it was moved to...
5
by: Nikolay Petrov | last post by:
I have a ListBox, which is binded to a DataTable. I would like to display a tooltip when the mouse cursor hovers over the items in the ListBox. I don't know how to find the index if ListBox item,...
2
by: markszlazak | last post by:
In the following script, a control displays (black box) in each table cell once you mouse over the cell. Mouse down on the control to change the mode of the table. Drag the mouse over cells in the...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.