Amadeu Cabanilles Amadeu Cabanilles - 1 month ago 5
HTML Question

adding a function in href using JQuery

I've just added this piece of code in my JSP

<script type="text/javascript">
$('a').click( function(e) {
e.preventDefault();
alert ('hello');
return false; } );
</script>


but nothing happens when I click to a

Answer

put your script in document.ready as, it will work

<script type="text/javascript">    
    $(document).ready(function()
        $('a').click( function(e) {
            e.preventDefault();
            alert ('hello');
            return false; 
        });
    )};
</script>
Comments