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