SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist Sikwondo's Avatar
    Join Date
    Sep 2005
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is this incorrect Javascript?

    Hi peeps,

    Sorry, am a bit of a JS novice, I am pulling in some JS for the Sons of Suckerfish Dropdowns and it is knocking all the code below out of whack...

    Is this incorrect?

    Code:
    <script type="text/javascript"><!--//--><![CDATA[//><!--
    
    sfHover = function() {
    	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
    	for (var i=0; i<sfEls.length; i++) {
    		sfEls[i].onmouseover=function() {
    			this.className+=" sfhover";
    		}
    		sfEls[i].onmouseout=function() {
    			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    		}
    	}
    }
    if (window.attachEvent) window.attachEvent("onload", sfHover);
    
    //--><!]]></script>
    Everything above the JavaScript is in the right colours in my HTML editor, and everything below is incorrect after the first <!-- of the <!--//--><![CDATA[//><!-- part.

    Sorry if I have been unclear, thank you in advance

    Si

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,872
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    If your edditor is colour coding HTML then obviously JavaScript (which isn't HTML will be colour coded incorrectly.

    You might consider keeping the JavaScript in a separate file so that the editor can colour code it as JavaScript instead of HTML.
    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="^$">

  3. #3
    SitePoint Evangelist Sikwondo's Avatar
    Join Date
    Sep 2005
    Posts
    426
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    If your edditor is colour coding HTML then obviously JavaScript (which isn't HTML will be colour coded incorrectly.

    You might consider keeping the JavaScript in a separate file so that the editor can colour code it as JavaScript instead of HTML.
    Thank you, will do that now.


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
  •