0

I have a javascript file and inside it there are some functions. I can call them on my rails app view through onclick events like: ...onclick="myFunnyFunction();"... and it works. But now I want to call this myFunnyFunction(); using the onload event like: onload="myFunnyFunction();". Both calls are in the same view file (one in a button and one in a div) and the onclick event work but the onload event don't. The div is showing the html properly so it is loaded.

Any suggestion?

Thanks in advance.

1 Answer 1

2

If body onload not works mean try this , operations are same

window.onLoad = doStuff()

function doStuff() {
   alert("test")
}

Fiddle Example

you cant do it div onload method but its posible you put script after div it will work

<div id="somid">Some content</div>
<script type="text/javascript">
   yourfunction()
</script>
Sign up to request clarification or add additional context in comments.

2 Comments

First of all thanks for your answer. In your case you launch the function when the body is loaded, but I want to launch the function when a particular div is loaded. Is that possible?
Great! it was simple but I couldn't figure it out. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.