Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable all A(URL) elements in DIV

Tags:

html

jquery

css

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?

like image 546
Tomas Avatar asked Sep 02 '10 06:09

Tomas


1 Answers

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;

});
like image 82
Pranay Rana Avatar answered Sep 30 '22 17:09

Pranay Rana