Search code examples
jqueryhtmlhyperlinkfinddisable-link

Find all link in a div element and disable them all


Assume that I have some HTML elements like these :

<div id="content_div">
    <span><a href="some_link">Click me</a></span>
    <div> Hello everybody. Click <a href="some_link_else">me</a> to do something else</div>

    <a href="3rd_link"> Oops </a>
</div>

All that I need is get all "a" tags in the #content_div and disable all of them (I don't want user to click on them). How could I do that in Jquery?


Solution

  • Try this:

     $("#content_div a").click(function(e) {
       e.preventDefault();
     });