fortnox007 Posted January 27, 2011 Share Posted January 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225873-could-someone-maybe-explain-what-happends-here/ Share on other sites More sharing options...
KevinM1 Posted January 27, 2011 Share Posted January 27, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/225873-could-someone-maybe-explain-what-happends-here/#findComment-1166115 Share on other sites More sharing options...
fortnox007 Posted January 27, 2011 Author Share Posted January 27, 2011 Thanks a lot Nightslayer! That sure helped me understand it more, I had a feeling about that last part. glad you confirmed it. I must have overlooked the regexpression, i normally see that. good I learned a new thing \b. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/225873-could-someone-maybe-explain-what-happends-here/#findComment-1166227 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.