HTML and CSS Reference
In-Depth Information
The Meaning of this
You might be a bit puzzled by the use of this as a variable name in an event han-
dler. Here, this is shorthand for the current object. When you're using an event han-
dler in a tag, this refers to the object represented by that tag. In the previous
example, it refers to the link that the user clicked on. The advantage of using this
is that it places the event in a useful context. I could use the same attribute value
with any link and the code would still work as expected. It's particularly useful when
you're using functions as event handlers and you want to make them easy to reuse.
You'll see a lot more of this in the next lesson.
At one time, using event-handler attributes to bind functions to events was the most com-
mon approach, but these days, it's more common to bind events to elements in other
ways. It's considered poor style to include JavaScript throughout your web pages, and
using the event-handler attributes can override event bindings that are applied from
JavaScript rather than in the HTML. In Lesson 15, I explain how to bind events to ele-
ments without changing your markup at all.
Learning More About JavaScript
The list of statements, functions, and options included in this lesson represents
only part of the potential offered by JavaScript.
For this reason, I cannot overemphasize the importance of the online documentation
provided by Netscape. All the latest JavaScript enhancements and features will be
documented first at
JavaScript enables HTML publishers to include simple programs or scripts within a web
page without having to deal with the many difficulties associated with programming in
high-level languages such as Java or C++.
In this lesson, you learned about the <script> tag and how it's used to embed JavaScript
scripts into an HTML document. In addition, you explored the basic structure of the
JavaScript language and how to use JavaScript in the browser environment.
With this basic knowledge behind you, in the next lesson, you'll explore some real-world
examples of JavaScript and learn more about the concepts involved in JavaScript pro-
Search WWH ::

Custom Search