从选择器中删除链接

时间:2013-09-20 19:02:10

标签: javascript ruby-on-rails

$('a').click(function(e) {
            e.preventDefault();
            newLocation = this.href;
            $('#monster').fadeOut('slow', newpage);
        });
        function newpage() {
            window.location = newLocation;
        }

我正在使用以下代码进行页面转换的淡出效果,每当我们点击任何链接时(" a"),我想删除带有id"的1个链接的此效果#flip",我该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以使用jQuery's :not selector。此外,我已将您的click函数切换为on事件处理程序,与速记click相比,它更灵活。个人喜好。

<强>的jQuery

$('a:not("#flip")').on('click', function(event) {
  event.preventDefault();
  // newLocation = this.href;
  // $('#monster').fadeOut('slow', newpage);
  alert('Only link tags without the #flip id should show this');
});

var newpage = function() {
  window.location = newLocation;
}

<强> HTML

<a href='#'>This link will work</a>
<a href='#'>This link will work</a>
<a href='#' id='flip'>This link will <b>not</b> work</a>

JS Fiddle example