Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9052745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T13:15:23+00:00 2026-06-16T13:15:23+00:00

Possible Duplicate: How to add onload event to a div? I am trying to

  • 0

Possible Duplicate:
How to add onload event to a div?

I am trying to draw a line with css and javascript as in the example here: example. I can get it to work just fine with the original stuff but after trying to modify it and then get it to work onload from the html onload equals its not working, but it is working with the onclick event.

here is my css:

.line 
{
    position: absolute;
    height: 0px;
    border-width: 2px 0px 0px 0px;
    border-style: solid;
    border-color: #99aadd;
 }

and the javascript:

function createLine2(myline,x1,y1,x2,y2)
{
    if (x2 < x1)
    {
        var temp = x1;
        x1 = x2;
        x2 = temp;
        temp = y1;
        y1 = y2;
        y2 = temp;
    }
    var length = Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
    myline.style.width = length+"px";
    var angle = Math.atan((y2-y1)/(x2-x1));
    myline.style.top = y1 + 0.5*length*Math.sin(angle) + "px";
    myline.style.left = x1 - 0.5*length*(1 - Math.cos(angle)) + "px";
    myline.style.MozTransform = myline.style.WebkitTransform = myline.style.OTransform="rotate("+angle+"rad)";
}

and finally the html that does not work:

<div class="line" onload="createLine2(this,100,100,0,0)">test</div><br>

and the html that does work:

<div class="line" onclick="createLine2(this,100,100,0,0)">test</div><br>

How do I get it to work with onload and what did I mess up?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T13:15:25+00:00Added an answer on June 16, 2026 at 1:15 pm

    The onload Event is not allowed on div Tags. It’s only allowed with the following tags:

    <body>, <frame>, <frameset>, <iframe>, <img>, <input type="image">, <link>, <script>, <style>
    

    http://www.w3schools.com/jsref/event_onload.asp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Add picture at facebook event with Graph API I have been trying
Possible Duplicate: jquery add a fade to an .addClass Here is my jsFiddle example:
Possible Duplicate: How to add 30 minutes to a javascript Date object? I can
Possible Duplicate: How to add a line break in an Android TextView? I'm trying
Possible Duplicate: CSS Select Selector I'm trying to add space on the left of
Possible Duplicate: Can you add a non-square drop shadow to PNG content with CSS?
Possible Duplicate: How can I add resizable widgets in Qt Creator? I am using
Possible Duplicate: VB.NET RemoveHandler & Anonymous Methods If I add an event handler like
Possible Duplicate: Automatically add an event handler to a newly created element using jQuery
Possible Duplicate: how to add new line to email contents? I want to send

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.