You could try the following:
$('a, div').click(
function(e){
return false;
// cancels default action *and* stops propagation
// or e.preventDefault;
// cancels default action without stopping propagation
});
MDC documentation for preventDefault
, jQuery documentation for event.preventDefault
.
SO question: JavaScript event.preventDefault
vs return false
.
I'm unsure as to the problem of the "href
still being available," since the click
event is cancelled; however if you want to remove the href
from a
elements:
$('a[href]').attr('href','#');
will remove them (or, rather, replace the URL with a #
).
Edited in response to comment (to question) by OP:
Ok, sorry ;) I just want to be able (by clicking on a button), to disable / enable all the links (click or href) over elements (div or a)
$('#buttonRemoveClickId, .buttonClassName').click(
function() {
$('a, div').unbind('click');
});
$('#buttonReplaceClickId, .buttonOtherClassName').click(
function() {
$('a, div').bind('click');
});