Jump to content

Script Hangs.


shadowayex
 Share

Recommended Posts

function reset(ulID){	var lis = document.getElementById("ul" + ulID).getElementsByTagName("li");	for(i = 0; i <= (lis.length - 1); i++)	{		lis[i].style.top = "0px";	}}

That function up there, for some ungodly reason, hangs on the 3 loop through (when i == 2). I really have no idea why or what could be going wrong. The ul it find exists and all the list it find have to exist. It just hangs on one of the above lines during the 3 round and repeats it over and over again until Firefox asks me if I want to stop it.The line varies, and has, so far, always been one of the 4 lines that make up the fop loop. Any explanation to this?If it helps, this is among many functions that sometimes are launching simultaneously. Although this is a "clean up" function, and is the last of chain that fire.

Link to comment
Share on other sites

Actually, I think I found the problem with this, and it doesn't have anything to do with the script itself.When I have onmouseout on a ul, it fires every time my mouse goes to another li inside of it. Thus, that function gets launched every time and with all the loops and everything, it breaks.Now the problem is, I don't know how to control this so when I switch li's, it doesn't count as a mouse out on the ul. Is this possible?Edit: Grammer error.

Edited by ragae
Link to comment
Share on other sites

I'm all evangelical about jQuery at the moment, but it's only because it's so easy to use. Using it, you can easily check the event target to see if it's an event function is being fired by the right event, and you can stop event propogation etc. But not using jQuery means all sort of message cross-browser event handling code. You should look into event bubbling and event capturing, as you can, I think, choose which type of event journey you want, which changes the way events are handled if they didn't originate in the element you want to trigger them.

Link to comment
Share on other sites

Well, different browsers handle events in different ways. The standard is event bubbling. This means that first of all the element that recieves the event most directly gets to react. For example, if you have text in a span in a paragraph in a div, if you click on the text and there is an event handler assigned to the span, it gets first dibs on reacting. Then the paragraph gets a go, then the div. This means, however, that if you have an onclick handler assigned to the div it is possible it will fire when the paragraph or span or text is clicked. Using jQuery, you can simply call event.stopPropogation() within the click handler for one of the lower level elements and it won't reach the higher level ones. For instance, you could assign a simple click handler to the list items that stops propogation, meaning it won't reach the ul. There are probably more succint ways to do it, although with jQuery it would only take a couple of lines to assign the same handler to ever li of a certain ul.

Link to comment
Share on other sites

I understand pretty much what you're saying now. Actually, I was able to solve the problem by reorganizing the events. What you said about the event bubbling is what helped my order the events in a way that works now. I'm still going to look into the other stuff you mentioned, because in a larger scale implementation of what I'm doing that JQuery stuff may become useful. Thanks for the info.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...