www.webdeveloper.com
Results 1 to 5 of 5

Thread: Using onLoad() function??

  1. #1
    Join Date
    Mar 2010
    Location
    Canada
    Posts
    80

    Using onLoad() function??

    I have this

    Code:
    <style>
      #mydiv{font-weight: bold;}
    </style>
    
    <div id="mydiv">This is in bold</div>

    If I wanted to, I can do this
    Code:
    <a href="#mydiv">This is in bold</a>

    But how do get it to call the class, "#mydiv" when the page first loads up??
    I tried
    Code:
    <body class="#mydiv">
    <body onload="#mydiv">
    but none of these code work. Any ideas??

    I know you can just call a function in javascript but how do I call a class in CSS??

  2. #2
    Join Date
    Nov 2013
    Posts
    72
    So href is used to create a hyperlink. If you wanted to link to another URL or another page on your site. The below code would take you to google by clicking "here".

    HTML Code:
    Go to google by clicking<a href='www.google.com'>here</a>
    Now to answer your question. JavaScript and the onload function is not needed to make something bold with CSS. Below will work, which is what you already have. I suppose I should ask what are you trying to do?

    HTML Code:
    <style>
      #mydiv{font-weight: bold;}
    </style>
    
    <div id="mydiv">This is in bold</div>

  3. #3
    Join Date
    Oct 2013
    Posts
    490
    Code:
    <meta http-equiv="refresh" content="0;url=mypage.htm#mydiv">
    will redirect the page to the "mydiv" id/section when the page loads

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,357
    Quote Originally Posted by Kevin2 View Post
    Code:
    <meta http-equiv="refresh" content="0;url=mypage.htm#mydiv">
    will redirect the page to the "mydiv" id/section when the page loads
    That kind of smells like an infinite redirect to me.

    I might try:
    HTML Code:
    <body onload="window.scroll(0,findPos(document.getElementById('mydiv')));
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Oct 2013
    Posts
    490
    Yeah, I think you're correct. Didn't have enough coffee in me yet when I suggested that.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles