www.webdeveloper.com
Results 1 to 5 of 5

Thread: very small problem .. what i've done wrong in my little code ?

Hybrid View

  1. #1
    Join Date
    Nov 2012
    Posts
    1

    very small problem .. what i've done wrong in my little code ?

    <html>
    <head>
    <script>
    function content(){
    alert (this.innerHTML);
    }
    </script>
    </head>
    <body>
    <div onclick='content(this)'>some text here</div>
    </body>
    </html>
    i get UNDEFINED when i click on the div ..

  2. #2
    Join Date
    Nov 2012
    Posts
    7
    You give your div an id
    Then need to feed your form with the id

    <head>
    <script>
    function myFunction(mydiv)
    {
    alert(document.getElementById(mydiv).innerHTML);
    }
    </script>
    </head>
    <body>
    <div id="mindiv" onclick="myFunction(this.id)">Click me</div>
    </body>

  3. #3
    Join Date
    Nov 2012
    Posts
    7
    Then need to feed your form with the id
    Then you need to call the function with the id

  4. #4
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,266
    Your need to write the function with an argument !
    Code:
    <html>
    <head>
    <script>
    function content(that){
    alert (that.innerHTML);
    }
    </script>
    </head>
    <body>
    <div onclick='content(this)'>some text here</div>
    </body>
    </html>
    An other solution consist to call the arguments array (here arguments[0]) in the function.
    Last edited by 007Julien; 11-21-2012 at 08:49 AM.

  5. #5
    Join Date
    Nov 2012
    Posts
    4
    function alertD(div){
    alert(div.innerHTML);
    }

    <div onclick="alertD(this);">Blablablablab</div>

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