Search code examples
jqueryjquery-ui-droppable

the attribute "href" of a <a> tag is a URL,but it calls functions after clicking the <a> tag.How it works


I found this question in jQuery UI demos.If you downloaded the jQuery UI,and so it located in "demos/droppable/photo-manager.html".

In this html page,there were several tags showing the delete icons in photo div.These tags' property named "href" are URLs,but it would call functions after clicking the tags. URLs->functions?How to do that?


Solution

  • You can attach a click event to a link and null the browser's default behaviour.

    HTML

    <a href="http://example.com">Example</a>
    

    jQuery

    $('a').click(function(event) {
       event.preventDefault();
       func();
    });