www.webdeveloper.com
Results 1 to 2 of 2

Thread: "this" keyword

  1. #1
    Join Date
    May 2010
    Posts
    2

    "this" keyword

    I don't know what it is but I still don't understand how to use the "this" keyword. Can anyone give me a simple explanation for it's use? Thanks.

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    All elements in a HTML document are actually objects with properties/attributes associated with each type of object/element.

    The 'this' keyword simply refers to the current object.

    for example:

    say you have an textbox whose value (user input) you want to have processed in some way whenever the user changes the text input.

    Code:
     
    <input type="text" id="txtInp" onchange="doSomething(this.value);" />
    The 'this' in this.value refers to the current object, which in this case is the <input> element and the 'value' in this.value refers to the current value of the textbox which is the user inputed text string.

    So if the user enters "hello world" in the textbox, the value "hello world" will be passed to the function doSomething();

    For further info on the Document Object Model (DOM), maybe have a look at this:

    http://www.w3schools.com/HTMLDOM/dom_intro.asp
    Last edited by tirna; 05-24-2010 at 05:10 PM.

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