More than one css class clickable in javascript

前端 未结 3 1139
小鲜肉
小鲜肉 2021-01-27 05:17

How can I do so that even \"toggle_cart\" is clickable in the same way as \"clickerHeader\" but retains its hover effect (see arrow)?

please see http://jsfiddle.net/real

3条回答
  •  Happy的楠姐
    2021-01-27 06:00

    A minimal change to your existing code is to add the following two lines after the first line of your click function:

    if ($elem.hasClass('toggle_cart'))
         $elem = $elem.next();
    

    In other words, if the span with the arrow is clicked, pretend that actually the anchor element was clicked. In context:

            $(document).on("click", function(e) {
                var $elem = $(e.target);
                if ($elem.hasClass('toggle_cart'))
                    $elem = $elem.next();
                if ($elem.hasClass('clickerHeader')) {
                // etc.
    

    Demo: http://jsfiddle.net/STE48/6/

提交回复
热议问题