English 中文(简体)
页: 1 通过j Query 加入后不取消等级
原标题:jQuery not removing class after being added through jQuery

今天上午,我似乎以<代码>removeClas陷入困境。 首先,我点击了<条码>div,添加<条码>集装箱式,然后,当我点击了尾子时,它将不去掉它刚刚添加到<条码>div的类别。

我不知道,这是否与它有某种关系,只添加到极地,而不是实际上装入超文本。 请有人帮助。

传真

<div class="container"></div>

页: 1 学历

$(function() {

    $( .container ).click(function(e) {
        var mythis = $(this);
        mythis.addClass("containerhover");
        mythis.find( .backface ).addClass("bfhover");
        mythis.find( .album ).addClass("ahover");
    });

    $( .closealbum ).click(function(e) {
        $( .container ).removeClass( containerhover );
    });
});
最佳回答

使用.on(>,将该活动附在集装箱内,如果点击.closealbum元素,则将其启动 only。 此外,添加<代码>event.Propagation()方法,以防止该活动进一步泡沫:

$( .container ).on( click ,  .closealbum , function(e) {
    $( .container ).removeClass( containerhover );
    e.stopPropagation();
});
  1. Your problem is caused by the fact that the .closealbum element does not exist when binding the click event.
  2. Your element is positioned inside the other element. Without e.stopPropagation(), the event bubbles up, and the first event will also be triggered, undoing the second event s removeClass.

Demo: http://jsfiddle.net/knCR8/1/

问题回答

暂无回答




相关问题
PHP DOM - accessing newly added nodes

I use the following to get a html document into DOM: $dom = new domDocument( 1.0 , utf-8 ); $dom->loadHTML($html) and then I add some new content to an element in the html: $element = $dom->...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

How to get a flash url in a webpage using a webframe?

As we know , When we load frame from webpage of safari, we will invoke the delegate methods of webkit informal protocol(WebFrameLoadDelegate): webView:didStartProvisionalLoadForFrame: webView:...

热门标签