Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-16-2013, 10:11 AM   PM User | #1
davidwhite
New Coder

 
Join Date: Nov 2011
Posts: 28
Thanks: 4
Thanked 0 Times in 0 Posts
davidwhite is an unknown quantity at this point
Question about DIV and JavaScript

I have this line of code:

<div class="blue" onclick="myfunction()" id="blue2">

This works fine and makes the JavaScript work if you click the Div.

Is there a way to make it so you don't have to click it, but it works automatically upon page load?

Thanks.
davidwhite is offline   Reply With Quote
Old 01-16-2013, 10:15 AM   PM User | #2
niralsoni
Regular Coder

 
Join Date: Mar 2008
Location: London
Posts: 143
Thanks: 3
Thanked 38 Times in 38 Posts
niralsoni is an unknown quantity at this point
Code:
<div class="blue" id="blue2">
<script>
myfunction();
</script>
niralsoni is offline   Reply With Quote
Old 01-16-2013, 10:52 AM   PM User | #3
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,105
Thanks: 197
Thanked 2,422 Times in 2,400 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
<body onload = "myfunction()">
<div class="blue" id="blue2">
Content of Div
</div>

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:53 AM.


Advertisement
Log in to turn off these ads.