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 zoom an image when it is clicked?
- How do I use jQuery to zoom in or out on an element?
- How do I use jQuery to set query parameters?
- How do I create a jQuery Yes/No dialog?
- How can I get the y position of an element using jQuery?
- How can I use JQuery with Yii2?
- How do I download a zip file using jQuery?
- How do I create a quiz using the jQuery plugin?
- How do I set the height of an element using jQuery?
See more codes...