I have a question regarding the jquery/javascript:
I’m in the following situation:
- I have a link
- It has a property onmouseover
- When I hover it calls a default FirstFunction(), this function replaces the image.
Note I’m not allowed to modify that FirstFunction(), as it executes some different important tasks.
What I want to do:
- Call a second function:
- The second function should replace the image back to original, so before it was changed by the before FirstFunction()
I wrote a following script:
function SecondFunction(obj) {
a = $(obj).find("img");
if (a != null && a.attr("src")!= null)
if (a.attr("src").lastIndexOf("img_4") != -1)
a.attr("src", "newSmallImg.png");
else if(a.attr("src").lastIndexOf("img_2")!=-1){
a.attr("src", "newBigImg.png");
}
}
Normally when I debug the script, it works etc etc, but the image is not replaced back. And i’ve noticed that “SecondFunction” is finished before the “FirstFunctions” is finished executing.
Can I do something about it? Like setting in SecondFunction => FirstFunction.ready? (The first function is also in a different file.)
Any input would be welcome
Small update, I’m calling the functions as follows:
<a onmouseover="FirstFunction(); SecondFunction(this);" ...>
<span>
<img src="" ... />
</span>
</a>
1) check the object type you’re receiving in your second function, how are you calling this function? can you provide the code?
2) check that the image your are finding in this line, is the one you expect:
I recommed to access the objects by an unique id: