开发者

jquery: not selector problem? [closed]

开发者 https://www.devze.com 2023-02-15 07:22 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

The following snippet applies a #breadcrumb hash to each link once it's clicked. That works fine.

$('#main a').live('click',function() {
    $(this).attr('href', $(this).attr('href') + "#breadcrumbs");     
});

Now I want to make sure that happens just if a link does not already have a #hash in it. Otherwise what happens is I click a link and the outcome looks like this: http://page.com/whatever#hash#breadcrumbs I simply want to prevent that.

However the following code does not work. If I add the :not selector none of the links adds the #breadcrumb hash (with or without already existing #hash)

开发者_如何学JAVA
$('#main a:not([href*="#"]').live('click',function() {
    $(this).attr('href', $(this).attr('href') + "#breadcrumbs");     
});

Any idea what I'm doing wrong here?


Your :not selector is missing a closing parenthesis. It should be:

$('#main a:not([href*="#"])').live('click',function() {
    $(this).attr('href', $(this).attr('href') + "#breadcrumbs");     
});
0

精彩评论

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