Help - Search - Members - Calendar
Full Version: this
HTMLHelp Forums > Programming > Client-side Scripting
pinklemon
Hello!
Pleas,e can somoene tell me what EXACTLY means "this" in next example:

CODE

<!DOCTYPE html>
<html>
<head>
<script>
function setStyle(x)
{
document.getElementById(x).style.background="yellow";
}
</script>
</head>
<body>

<p>A function is triggered when one of the input fields get focus. The function changes the background-color of the input field.</p>
First name: <input type="text" id="fname" onfocus="setStyle(this.id)"><br>
Last name: <input type="text" id="lname" onfocus="setStyle(this.id)">

</body>
</html>


Many thanks!!!
Christian J
Please try to post new threads in relevant sub forums. This one seems to be about client side javascript, so I moved the thread here.
Christian J
QUOTE(pinklemon @ Jul 5 2014, 08:12 PM) *

can somoene tell me what EXACTLY means "this" in next example:

CODE
<input type="text" id="fname" onfocus="setStyle(this.id)">


In that example it means the HTML element. In other contexts it can mean other things. See http://quirksmode.org/js/this.html for details.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.