SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Post what does this mean in javascript?

    Hi, I need some help on this, I saw a piece of code of javascript and i was confused on this,can you help me please or enlighten my mind,what does this javascript mean or how this behave.Thank you in advance.

    this.className=this.className.replace(new RegExp(" over\\b"), "");



    Code:
    <!--[if lt IE 7]>
    <script type="text/javascript">
    sfHover = function() {
    	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    	for (var i=0; i<sfEls.length; i++) {
    		sfEls[i].onmouseover=function() {
    			this.className+=" over";
    		}
    		sfEls[i].onmouseout=function() {
    			this.className=this.className.replace(new RegExp(" over\\b"), "");
    		}
    	}
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
    </script>
    <![endif]-->

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,879
    Mentioned
    208 Post(s)
    Tagged
    12 Thread(s)
    This code adds :hover functionality to IE6 and below (as IE6 only supports the :hover pseudo-class on anchor tags).
    In the line you ask about, "this" refers to a <li> element of an unordered list with the id "nav".
    The script will apply a class of "over" to the <li> element in question when you mouse over it.
    It will then remove the class as soon as you move your mouse away.

  3. #3
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    It means take the classname from "over" to empty. Meaning their would be no class for LI.
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  4. #4
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi, Thank you for the reply..what about this line

    replace(new RegExp(" over\\b"), "");
    why he uses the RegExp? and what does this
    over\\b
    mean?

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,786
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    The \\b is a regular expression code for a word boundary in that position it will match any whitespace character or the end of the text.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    SitePoint Wizard
    Join Date
    May 2012
    Posts
    1,087
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi felgall,thank you for the reply and for explaining me.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •