开发者

jQuery if and logic

开发者 https://www.devze.com 2022-12-24 07:01 出处:网络
I have a simple jQuery toolbar, the basic functionality is: Hover: Background change to defined value & add .active class

I have a simple jQuery toolbar, the basic functionality is:

  1. Hover: Background change to defined value & add .active class
  2. OnClick: Move the icon down 4px, and change background of the toolbar to that of the element

What I would like to do move the icon down 4px when it has the clas开发者_如何学Gos 'active' applied, however also remove the onclick event?

Somehow I need an 'IF' statement in my jQuery for the Onclick event.


for the if part you could use the active class as a flag..

so inside the click handler

if ( !$(this).hasClass('active') ) {
  // do what you want
}

which translates to "if the clicked element does not have the active class assigned then do what you want to do" ...

0

精彩评论

暂无评论...
验证码 换一张
取 消