its idea is that you can also use the live() method to enable/disable events. What will happen with this code is that when you click on an a tag-element, for instance, .load-item, it will add the class disabled to this element. This will make it so that the selector no longer matches the element and the event will not be fired until the ‘disabled’ class is removed making the .live() selector valid again.
Below is what I came out with and it does disable the click on the first button,
$('.load-item:not(.disabled)').live('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').each(function(index) {
$(this).addClass('disabled');
});
....
});
and I have another function to remove the disabled-class when you click on the other button,
$('.button-return').click(function(){
...
/* remove all the .disabled class if any exists */
$('.current a').each(function(index) {
$(this).removeClass('disabled');
});
...
/* remove all the .current class if any exists */
$('.item-global').removeClass('current');
return false;
});
I have checked that it does remove the disabled-class, but the first button still is not back on to the original clickable state.
have I missed out anything - or the live() actually only lives once only? any better solutions if live() is not the one I should work on??
thanks for the reply. tried it and the same result as live(). I found out what the problem is in my code - 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>
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;
});