following up on this thread jquery: live() – only lives once? I found out what the problem is in my code whether I use live() or bind() – I have this line below after using load(),
$('.disabled').click(function(){return false;});
If I don’t use this line the page will ‘return’ the link in the a tag if I click on the button again. for instance, this is the first button (a text link button) –
<a href="another_page.php">button 1 </a>
what have I done wrong by adding that line? any idea how I can resolve this…?
below is some more code of this function I am trying to resolve this problem,
$('.load-item-news:not(.disabled)').bind('click',function(){
...
/* add a .current class to the target item */
$(this).parentsUntil('.column-global').addClass('current');
/* add .disabled class to each a tag in the .current element-div */
$('.current a').addClass('disabled');
...
/* prepend a fresh div */
$('.column-global.right').prepend('<div class="wrapper-item"></div>');
...
var path = $(this).attr('href');
var item_wrapper = $('.wrapper-item');
var array_path = path.split('/');
var pg_url = $(array_path).last()[0];
item_wrapper.load(http_root+rp_template+'item_content_news.php?pg_urlx='+pg_url, function(){
...
$('.disabled').click(function(){return false;});
//$('.current a').click(function(){return false;});
});
return false;
});
thanks.
When you do this:
…you do two things by returning
false:You prevent the browser default (like
event.preventDefault()), andYou prevent the event from bubbling up the DOM (like
event.stopPropagation()).If you only want to do one or the other (like just preventing the default), you can do that:
That way you’re preventing the default action but not stopping bubbling, and so any
livehandler you have should eventually be triggered.But I wonder if you really want to be doing this. I’m guessing if a link can have the class “disabled”, that it can be “enabled” sometimes? Just removing the “disabled” class won’t turn off that click handler (that’s part of what
liveis for, handling changes for you). For instance:…tells jQuery that rather than looking for elements that have the class “disabled” now, you want it to check when the click occurs and only run the handler if the element matches at that point in time.