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.
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.
say you have an textbox whose value (user input) you want to have processed in some way whenever the user changes the text input.
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.
<input type="text" id="txtInp" onchange="doSomething(this.value);" />
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:
Last edited by tirna; 05-24-2010 at 05:10 PM.
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)