SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    w3school: what is "this"?

    Please, I appologise, but what exactly is menaing "this" in front of inner...in this code:

    Code:
    <!DOCTYPE html>
    <html>
    <body>
    
    <h1 onclick="this.innerHTML='Ooops!'">Click on this text!</h1>
    
    </body>
    </html>
    Many thanks!

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,173
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    If you're really interested in learning javascript, then you really ought to stop using w3schools for your education.
    For example, that code uses inline javascript. Not best practice for quite a while now.

    Anyway, "this" pretty much means what common sense suggests it means. You can read about it in this much better (compared to w3schools) site https://developer.mozilla.org/en-US/...Operators/this

  3. #3
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,198
    Mentioned
    456 Post(s)
    Tagged
    8 Thread(s)
    It basically means "change the text of this element to 'Ooops!' when it's clicked on".

    As said, though, it's lousy code, so don't use it, but read the reference supplied instead.


Bookmarks

Posting Permissions

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