0

I'm trying to load a few div's using JQuery .load(), one of those being the div containing the links from where to load from. Here's the code:

$(".category").click(function(e){
    e.preventDefault();
    var link = $(this).attr("href");

    $('#right_options').load(link+' #right_options');
    $('#center_content_title').load(link+' #center_content_title');
    $('#center_content').load(link+' #center_content');
});

The first time works great but the second time instead of loading using jquery it loads the entire page by following the link, not detecting the click, the class or something. Where's the problem on loading like this?

1
  • Are you certain your selector exists in the loaded page? Commented Sep 28, 2011 at 16:43

1 Answer 1

1

Do any of those three load calls change the a element, i.e., the $(".category") element? If so, then the binding done through the call to .click is removed when the element changes. If that is the case, you'll need to use .live("click", ... instead of the click method. Or in other words, you would replace this:

$(".category").click(function(e){

with this:

$(".category").live("click", function(e) {
Sign up to request clarification or add additional context in comments.

1 Comment

That was precisely the problem! The .category was the link class inside the div #right_options which was one of the things being loaded. Wasn't aware of the binding precautions needed, thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.