Home>Article>Web Front-end> How to determine if the mouse is on a div with jquery

How to determine if the mouse is on a div with jquery

coldplay.xixi
coldplay.xixi Original
2020-12-07 16:23:12 4130browse

Judgment method: First use the onmouseover attribute to bind the mouse event to the div. When the mouse moves to the div, the onmouseover mouse event will be triggered, the myfun() function will be executed, and then the alert() method in the myfun function will be executed. , and then trigger the pop-up prompt [mouse is on div].

How to determine if the mouse is on a div with jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

Recommended:jquery video tutorial

Jquery method to determine whether the mouse is on a div:

1. Create a new html The file, named test.html, is used to explain how jquery determines whether the mouse is on a div.

How to determine if the mouse is on a div with jquery

2. In the test.html file, use div to create a module and set its id to mydiv. Mainly use the following to set its css style.

How to determine if the mouse is on a div with jquery

3. In order to show obvious effects, set the css style of the div through the id, set the width and height of the div to 100px, and set the background color to red.

How to determine if the mouse is on a div with jquery

4. In the test.html file, bind theonmouseover()event to the div. When the mouse moves to the div, the event is triggered and executed.myfun()Function.

How to determine if the mouse is on a div with jquery

5. In the js tag, create a myfun() function. When the function is called, execute the code in the method body.

How to determine if the mouse is on a div with jquery

6. In themyfun()function, use the alert() method to prompt "The mouse is on the div!!" and confirm that the mouse is on on div.

How to determine if the mouse is on a div with jquery

7. Open the test.html file in the browser, move the mouse to the div to view the results.

How to determine if the mouse is on a div with jquery

Related free learning recommendations:javascript(Video)

The above is the detailed content of How to determine if the mouse is on a div with jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn