Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the difference between hover () and toggle () in jQuery

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces what is the difference between hover () and toggle () in jQuery, which can be used for reference by interested friends. I hope you can learn a lot after reading this article.

What's the difference between hover () and toggle () in jQuery?

Hover (fn1,fn2): a method that mimics hovering events (moving the mouse over and out of an object). When the mouse moves over a matching element, the first function specified is triggered. When the mouse moves out of this element, the second function specified is triggered.

/ / set class to over when the mouse is over a row of the table, and out when leaving. $("tr") .hover (function () {$(this) .addClass ("over");}, function () {$(this) .addClass ("out");})

Toggle (evenFn,oddFn): toggles the function to be called each time you click. If a matching element is clicked, the first function specified is triggered, and when the same element is clicked again, the second function specified is triggered. Each subsequent click repeats the call to these two functions.

/ / rotate to add and delete a class named selected with each click. $("p") .toggle (function () {$(this) .addClass ("selected");}, function () {$(this) .removeClass ("selected");}) Thank you for reading this article carefully. I hope the article "what's the difference between hover () and toggle () in jQuery" shared by the editor will be helpful to you. At the same time, I hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report