I have such html code
<div>
<p>MY Text <a href="url">Text</a>
</p>
</div>
I need using CSS or jQuery disable all A elements in DIV, when user move mouse over Text the URL is not active and he can't click on it. How to do that?
I have such html code
<div>
<p>MY Text <a href="url">Text</a>
</p>
</div>
I need using CSS or jQuery disable all A elements in DIV, when user move mouse over Text the URL is not active and he can't click on it. How to do that?
To prevent an anchor from following the specified HREF, I would suggest using preventDefault():
$(document).ready(function() {
$('div a').click(function(e) {
e.preventDefault();
});
})
See:
http://docs.jquery.com/Events/jQuery.Event#event.preventDefault.28.29
or
$("div a").click(function(){
alert('disabled');
return false;
});
$('div a').click(function(e) { e.preventDefault(); });
If you don't want the links to appear as links, as Sjoerd says you can remove the href
attribute instead:
$('div a').removeAttr('href');
(This might depend on whether the styles point to a
or a:link
though, I'm not entirely sure.)
$(document).ready(function () {
$('div').hover(function(){
$(this).find('a').attr('disabled','disabled');
},function(){})
});
But why would you do that?