简体   繁体   中英

Prototype/Javascript DOM-Element ID as parameter

I want to hand over an id to a Javascript function as a parameter (inRef) and then process it with the protoype Fade.Effect. My function looks as follows:

<script type="text/javascript">
    function fadeEffect(inRef) {
        $(inRef).fade({ duration: 1.8, from: 0.7, to: 1 });
    } 
</script>

Firefox and Opera can handle it correctly, whereas Chrome and Safari throw a console error saying inRef is undefined. I hand over the inRef as a string and think Javascript needs it as something else (JSON?)

Thanks for any help.

Inside the function alert(typeof inRef) to check whether inRef is cast as a string in webkit browsers.

function fadeEffect(inRef) {
        alert(typeof inRef);
        $(inRef).fade({ duration: 1.8, from: 0.7, to: 1 });
} 

If its not, cast it as a string

function fadeEffect(inRef) {
        $(inRef.toString()).fade({ duration: 1.8, from: 0.7, to: 1 });
} 

inRef can be a string since $(inRef) turns it into an object reference. Perhaps the problem lies somewhere else. What happens if you use the literal instead of the variable?

$("divname").fade({ duration: 1.8, from: 0.7, to: 1 });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM