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");
});
精彩评论