I have a script that is looking for a live click event, but I am wanting the click to not apply to certain <a> tags
Here is my code so far:
$('a:not(.btn-control)').filter(function(index) {
return $(this).attr('href').match(/#|void/);
}).live("click", function() {
var url;
url = $(this).attr('href');
url = url.replace(/^.*#/, '');
$.history.load(url);
return false;
});
Issue
I have site where I have a static player, upon the clicking of a link I am using the HTML5 history functionality to load the new content so that the page never refreshes… to avoid having to go throughout my whole site and add classes to all of the links that should contain this functionality onClick, I am simply trying to filter out those with a # or a javascript:void(0) in the href
Question
How do I filter out those links whose href contains a javascript:void(0) or a #?
Working Code
$('a:not(.btn-control)').live("click", function() {
var self, url;
self = $(this);
url = self.attr('href');
if (url.match(/#|void/) === null) {
url = url.replace(/^.*#/, '');
$.history.load(url);
return false;
}
});
The jQuery docs state that:
Instead, you should handle all
atags, but exit out if you don’t need to handle it.