sam levene
sam levene

Reputation: 9

(jquery) .load and .live

I've loaded content1.html into a div using .load (WHICH WORKS FINE).

Now I want to put a link in the content1.html content that when clicked would load content2.html into the div. Any ideas how I would do this? At the moment I've got:

google.setOnLoadCallback(function() {
    $('#howtoguide6').live('click', function() {

        $("#howtoguide6").click(function(){
            $("#hiw-content-area").load("pages/hiw/how_to.html");
            return false;
        });
    });
});

Basicly I've already loaded

google.setOnLoadCallback(function() {
$("#choose_design_service").click(function(){
    $("#hiw-content-area").load("pages/hiw/what_we_need_from_you.html");
    return false;
    });
});

-which works fine, I now have want to add something to "pages/hiw/what_we_need_from_you.html" that will load "pages/hiw/how_to.html" into the "#hiw-content-area".

I think where I'm having trouble is doing this from inside already loaded content.

Upvotes: 0

Views: 1199

Answers (3)

StuperUser
StuperUser

Reputation: 10850

Take out the call to `click()'.

google.setOnLoadCallback(function() {
    $('#howtoguide6').live('click', function() {
            $("#hiw-content-area").load("pages/hiw/how_to.html");
            return false;
    });
});

Your original code wasn't working because click() is a shortcut to the function bind('click'). live() is similar to bind(), except that the results of the selector do not have to exist in the DOM. So your code was binding a function to click that bound the function to click again, rather than running the code in the handler.

Taking out the call to click will simply run the handler when the element is clicked, since (you have bound to the element using live().

Upvotes: 1

Frenchi In LA
Frenchi In LA

Reputation: 3169

what i don't understand is the second click binding. have you tried :

google.setOnLoadCallback(function() {
$('#howtoguide6').live('click', function() {
        $("#hiw-content-area").load("pages/hiw/how_to.html");
        return false;
});

});

Upvotes: 0

Felix Kling
Felix Kling

Reputation: 816770

I assume (you don't explain which element is which), that you want:

$('#howtoguide6').live('click', function() {
    $("#hiw-content-area").load("pages/hiw/how_to.html");
    return false;
});

Upvotes: 4

Related Questions