Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Jul 2011
    Posts
    184
    Thanks
    68
    Thanked 2 Times in 2 Posts

    replace empty <div> with text after clicking a link

    How to get this to work?

    Code:
    <html>
    <body>
    <script type="text/javascript" src="01.js">
    <h1>Welcome</h1>
    <a href="#" onclick="write(); return false;">Click here</a>
    <div id="info_here">
    </div>
    </body>
    </html>
    01.js
    Code:
    function write() {
    var a=document.getElementById("info_here");
    a.innerHTML=document.write("Hello <br />" + "Thanks for clicking");
    }

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    write is a reserved JavaScript word. And write() is not a dynamic method. innerHTML is enough.

    Code:
    <a href="#" onclick="doWrite(); return false;">Click for info</a>
    Code:
    function doWrite() {
    var a=document.getElementById("info_here");
    a.innerHTML="Hello<br />Thanks for clicking";
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • Users who have thanked Kor for this post:

    joliett89 (10-10-2011)

  • #3
    Regular Coder
    Join Date
    Jul 2011
    Posts
    184
    Thanks
    68
    Thanked 2 Times in 2 Posts
    This is working, thanks.


  •  

    Posting Permissions

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