Passing parameters to function from within setTimeout ?

Posted on 2006-04-06
Last Modified: 2008-02-01
Hi all

I've got a SwitchMenu function that hides or shows a div tag onMouseOver...and I'm trying to introduce a delay of half a second or so ...but I can't seem to pass the 'sub3' parameter to the function correctly from my code ...can someone offer advice?

This is my code without the setTimeout:
            <div class="navHeaderCursorArrow" onMouseOver="SwitchMenu('sub3')">Secure Login</div>

works fine ...

Then i try adding the setTimeout:
            <div class="navHeaderCursorArrow" onMouseOver="setTimeout('SwitchMenu()', 1250, 'sub3');">Secure Login</div>

and not working at all :-(

btw SwitchMenu function is below:

                  function SwitchMenu(obj){
                        var el = document.getElementById(obj);
                        var ar = document.getElementById("masterdiv").getElementsByTagName("span"); // change
                              if( != "block"){ // change
                                    for (var i=0; i<ar.length; i++){
                                          if (ar[i].className=="submenu") // change
                                          ar[i].style.display = "none";
                           = "block";
                           = "none";
Question by:msiedle
    LVL 75

    Accepted Solution

    setTimeout does not work like that...


     <div class="navHeaderCursorArrow" onMouseOver="setTimeout('SwitchMenu(\'sub3\')', 1250);">Secure Login</div>
    LVL 2

    Author Comment

    great :-)


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    "That which we persist in doing becomes easier, not that the task itself has become easier, but that our ability to perform it has improved." Ralph Waldo Emerson Introduction: One of the wonderful things about the web is that it makes it s…
    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now