Can jQuery.live stop the browser after the link?

I am trying to use $ (). live to improve the site, but he insists on the next href. The following is very close to the real code (a.class, span inside a).

<a class="test" href="http://google.com"><span>test</span></a>

$('a.test').live('click', function(event){
    event.preventDefault();
    $(this).text('clicked');
});

Testing this in jsfiddle works , but not when I use it in my project. The handler starts, but href also executes. I tried and return false and event.preventDefault () with the same result.

Try so that I can not find anything that could interfere with the work on my site.

So my question is should this ever work? If so, is there something that could not do this?

+3
source share
4 answers

, jQuery mobile. $.mobile.ajaxEnabled = false location.href = $this.attr( "href" );, data-ajax="false". jQmobile , nav.

jQuery

+2

href , , .

, , href window.location live(), , .

0

, jquery

$(document).ready(function(){

   // your code here?

});

jsFiddle. http://jsfiddle.net/vG5gW/1/

jsFiddle, , , DOM script .

0

I see that you say what you CAN do is point out the id link and set jquery to href. If javascript is not available, the link will remain intact, if not, then the href link will be changed to # or whatever you would like.

0
source

Source: https://habr.com/ru/post/1796714/


All Articles