Need to learn JavaScript?
jQuery is a JavaScript framework, so if you don't already know about the JavaScript programming language, we recommend that you learn it now:
Learn JavaScript
The community is working on translating this tutorial into Norwegian Bokmål, but it seems that no one has started the translation process for this article yet. If you can help us, then please click "More info".
If you are fluent in Norwegian Bokmål, then please help us - just point to any untranslated element (highlighted with a yellow left border - remember that images should have their titles translated as well!) inside the article and click the translation button to get started. Or have a look at the current translation status for the Norwegian Bokmål language.
If you see a translation that you think looks wrong, then please consult the original article to make sure and then use the vote button to let us know about it.
Metadata
Please help us by translating the following metadata for the article/chapter, if they are not already translated.
If you are not satisfied with the translation of a specific metadata item, you may vote it down - when it reaches a certain negative threshold, it will be removed.
Please only submit an altered translation of a metadata item if you have good reasons to do so!
Please
login to translate metadata!
Already logged in? Please try reloading the page!
Events:
Introduction to events
Events in JavaScript are usually something where you write a snippet of code or a name of a function within one of the event attributes on an HTML tag. For instance, you can create an event for a link by writing code like this:
<a href="javascript:void(0);" onclick="alert('Hello, world!');">Test</a>
And of course this is still perfectly valid when using jQuery. However, using jQuery, you can bind code to the event of an element even easier, especially in cases where you want to attach anonymous functions or use the same code for multiple events, or even the same code for multiple events of multiple elements. As an example, you could bind the same event to all links and span tags in your document, with only a few lines of code like this:
<script type="text/javascript">
$(function()
{
$("a, span").bind("click", function() {
alert('Hello, world!');
});
});
</script>
We use the bind method, which is essential when working with events and jQuery. In the following chapters we will tell you more about how it works, along with other event related information you need.
This article has been fully translated into the following languages:
Is your preferred language not on the list?
Click here to help us translate this article into your language!