|
-
March 17th, 2003, 09:30 AM
#1
Collection
Hello, friends.
I´m in trouble with a simple code, but i don´t know how to solve this question.
I have a home page, with one tag with the same id and I need to know the index of an id when the mouse passes over the tag..
The property sourceIndex does not work on this case, as i just have tested.
How can I get the index of some specific id in that collection ????
See below my sample html code:
<HTML>
<HEAD>
<SCRIPT for=linkMenu event=onmouseover>
if window.LinkMenu.sourceIndex = 1 {
window.alert('1');
{
else {
window.alert('2');
}
</SCRIPT>
<BODY>
<A id=LinkMenu href="main.htm">Test 1</A>
<A id=LinkMenu href="old_main.htm">Test 2</A>
</BODY>
</HEAD>
</HTML>
-
March 17th, 2003, 11:41 AM
#2
Just pass the object itself in the mouseover with the "this" keyword.
You can change your mouseover to pass "this" which will be a reference to the object. For instance:
<A HREF="blahblah" onMouseover = "doSomething(this)")>asdf</A>
<SCRIPT>
function doSomething(linkObject){
if(linkObject.tagName == "A"){
alert(this.innerText);
}
}
</SCRIPT>
Hope this helps
Nate Grover
http://www.nategrover.com
-
March 17th, 2003, 12:01 PM
#3
Collection
Thanks, friend !
In fact, I need to know the index of the element in the collection that was built by browser.
The browser created an collection using my code.
Thanks !
-
March 17th, 2003, 01:21 PM
#4
Ok, if you need to know the index, and the links are being generated by your code, you can just put the index into the id.
BTW, an ID is supposed to be unique. Names can be duplicated but only one instance of an ID can be identified by the DOM.
So, your links should look like this:
<A ID="linkMenu_1" HREF="asdf">test1</A>
<A ID="linkMenu_2" HREF="asdf">test2</A>
<A ID="linkMenu_3" HREF="asdf">test3</A>
Now when your mouseover sends "doSomething(this)", you can parse the index out of the id.
If for some reason that doesn't work for you , you can always start traversing the DOM based on your link object. Like this:
function doSomething(link){
prevLink = link.previousSibling;
index = 0;
while(prevLink != null){
if(prevLink.tagName == "A") && prevLink.className == "menuLinkClass") index++;
prevLink = prevLink.previousSibling;
}
currentLinkIndex = index;
}
Hope this helps.
Nate Grover
http://www.nategrover.com
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|