I tried to use this jQuery selector:
$("a:has(href*=#)").click(function() {
alert('works');
});
but it doesn't seem to work. I would like to select all tags which have anchor in href attribute (has # symbol there)
I tried to use this jQuery selector:
$("a:has(href*=#)").click(function() {
alert('works');
});
but it doesn't seem to work. I would like to select all tags which have anchor in href attribute (has # symbol there)
*=
will filter attributes that contain the given string anywhereAlso note that
will select any anchor whose href starts with a
#
You've got to select using the attribute starts with selector:
Check out my jsfiddle!