www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] About the THIS element.

  1. #1
    Join Date
    Dec 2012
    Posts
    20

    resolved [RESOLVED] About the THIS element.

    Hi there guys I wanted to know what is the "this" element in the following two codes and what it does?

    Code:
    <h1 onclick="this.innerHTML='Ooops!'">Click on this text!</h1>
    Code:
    <div onmouseover="mOver(this)" onmouseout="mOut(this)" style="background-color:#D94A38;width:120px;height:20px;padding:40px;">Mouse Over Me</div>
    thanks.

  2. #2
    Join Date
    Aug 2008
    Location
    Sweden
    Posts
    227
    'this' is kind of a special variable and can reference different things in different places. However, in your cases here the 'this' variable refers to the HTML element in which the JavaScript code is located in.

    So in your first code block 'this' refers to the h1 element, and in your second code block 'this' refers to the div element.

  3. #3
    Join Date
    Dec 2012
    Posts
    20
    thanks for the reply

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