Skip to content Skip to sidebar Skip to footer

Give This Function An Id

We are making a advert div, and we have this function on mouse over and mouse out an effect takes place. The issue is I cannot run more than one of these functions on same page, I

Solution 1:

If you want the same function to be binded to different elements, if correclty binded this is a reference to the source of the event (the div to which the event is attached). That should allow you to bind the same function to different elements. In your code just replace document.getelementbyid("flashdiv") for this.

Solution 2:

Assuming these are event handlers, we are missing the code registering them. You could write a function taking the id which returns an event handler for one div in the following way:

functioncreateMouseOver(id) {
    returnfunction () {
        document.getelementbyid(id).classname="flash-abg";
    }
}

Then register the result of createMouseOver('someid'), which is a function with the correct id in its closure.

Alternatively, don't use ids at all and find all your ad divs by class -- and register event handlers for all elements found by class.

Post a Comment for "Give This Function An Id"