jqueryHow do I use jQuery to create a mouseover event?
To use jQuery to create a mouseover event, you can use the .hover()
method. This method takes two functions as parameters, the first for the mouseover
event and the second for the mouseout
event.
For example:
$("#example").hover(
function(){
alert("You entered #example!");
},
function(){
alert("Bye! You now leave #example");
}
);
When the mouse hovers over the element with the id example
, an alert message will appear saying "You entered #example!" and when the mouse moves out of the element, an alert message will appear saying "Bye! You now leave #example".
The parts of the code are:
$("#example")
: This is a jQuery selector which selects the element with the idexample
..hover()
: This is a jQuery method which takes two functions as parameters.function(){}
: This is an anonymous function which contains the code that will be executed when the event is triggered.alert("You entered #example!");
: This is an example of code which will be executed when the mouse hovers over the element.
Helpful links
More of Jquery
- How do I use jQuery ZTree to create a hierarchical tree structure?
- How do I use jQuery to zip files?
- How do I use jQuery to detect window resize events?
- How do I download a zip file using jQuery?
- How can I get the y position of an element using jQuery?
- How do I use a jQuery x-csrf-token?
- How do I add a zoom feature to my website using jQuery?
- How can I prevent jQuery XSS vulnerabilities?
- How can I use jQuery to yield a result?
- Include latest jQuery library version into HTML
See more codes...