Jump to content

Could someone maybe explain what happends here


fortnox007

Recommended Posts

Hi all, i am using a little snippet to mimic the hover effect to other elements than A for IE 6 and lower. But since i am a complete noob in javascript i thought i ask some guru's what is happening here. The code is part of the suckerfish menu script.

 

I made some comments in the script of what i think that happends. but i am not sure. its a wild uneducated guess.

sfHover = function() { //declare function
var sfEls = document.getElementById(“nav”).getElementsByTagName(“LI”); //assign variable sfEls with the 
                                                                                                 //value of <LI> element in a menu with id #nav
for (var i=0; i
sfEls[i].onmouseover=function() {
this.className+=" sfhover"; // looks like a classname is assigned on mouseover to the LI inside #nav?
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\b"), ""); // no idea what \b means
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover); // no idea either

 

 

Any explanation would be great, since i rather not implement snippets i don't fully understand.

Link to comment
Share on other sites

For the '\b', take a look here: http://www.regular-expressions.info/wordboundaries.html  The mouseout function is removing the sfhover class from the elements that don't need them.

 

For the last bit, it's simply attaching the sfHover function to the window's onload event.  When the window is loaded, the hover functions will be loaded and ready to work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.