I have this html code
<div>
<p>MY Text <a href="url">Text</开发者_开发问答a>
</p>
</div>
I need to use CSS or jQuery disable all A (link) elements in a DIV, when the user moves the mouse over the word: "Text", I want the URL to be inactive so they can't click on it. How do I 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: Event Object
or
$("div a").click(function(){
alert('disabled');
return false;
});
$(document).ready(function () {
$('div').hover(function(){
$(this).find('a').attr('disabled','disabled');
},function(){})
});
But why would you do that?
- Remove the href attribute; or
- Bind an onClick handler which returns false;
精彩评论