• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

SetTimeOut with element


 I am trying to pass the element information into the timer.

This is how it should be works.
After mouse over the "show menu 0"
the other information below it should display after 500 milliseconds.
<html>
<head>
<script language="JavaScript" type="text/javascript">
//onmouseover show the drop down menu
	var timeout;
	function delay_master(elem,method){
		timeout = setTimeout("delay_master2(elem,method)",500);
	}
	function delay_master2(elem,method){
		alert("o"+elem)
		elem.childNodes[2].style.display=method
		clearTimeout(t);//clear timer after displayed
	}
	
	function AddClass(elem) {
		elem.className = "iehover";
		//elem.childNodes[2].style.display="block"; 
		delay_master(elem,'block');//passing command to delay master
	}
	function RemoveClass(elem) {
		elem.className = "";
		//elem.childNodes[2].style.display="none"; 
		delay_master(elem,'none');//passing command to delay master	
	}
        </script>

</head>
<body>                
<li  onmouseover="AddClass(this);" onmouseout="RemoveClass(this)" ><a href="search/?no_cat=y&amp;cat_id=1%26cat_name=show menu">show menu 0</a>
    <ul style="display:none">
    <li  style="clear:both; width:320px; margin-left:-20px;text-align:left; background-color:red">
    <p><a href="search/?cat_id=1&amp;cat_name=Apparel&amp;sub_cat_id=1&amp;sub_cat_name=Aprons">Aprons</a></p>
    </li>
    </ul>
</li>

<li  onmouseover="AddClass(this);" onmouseout="RemoveClass(this)" ><a href="search/?no_cat=y&amp;cat_id=1%26cat_name=show menu">show menu 1</a>
    <ul style="display:none">
    <li  style="clear:both; width:320px; margin-left:-20px;text-align:left; background-color:red">
    <p><a href="search/?cat_id=1&amp;cat_name=Apparel&amp;sub_cat_id=1&amp;sub_cat_name=Aprons">Aprons 2</a></p>
    </li>
    </ul>
</li>




</body>
</html>

Open in new window

0
jsdebugger
Asked:
jsdebugger
1 Solution
 
jello024Commented:
setTimeout will fire outside the scope of the funtion it was called in. So in this case elem and method would not be recognized.  Give the element an id and try this:

setTimeout("delay_master2(document.getElementById('" + elem.id + "'), '" + method + "')",500);
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now