ianrey palo
ianrey palo

Reputation: 61

Loading another page with jquery-Ajax

I am loading another html page from an index page, then I would like to get an element from that loaded page, but the page seems not loaded yet since the element resulted to null, even if there is a function call back with in the ajax load function:

$(document).ready(function() {

$('#btnEdit').click(function(){


    $('#contents').load("abcd.html",showNewcontents())


    function showNewcontents() {

        alert("" + document.getElementById("make").value);
    }

return false;

});

});

in body:

<body>

<a href="click me" id="btnEdit" name="btnEdit">CLICK ME </a>

<div id="contents"></div>

</body>

in abcd.html:

<div id="contents">


<form> 

<input type="hidden" id="make" name="make" value="make">

</form>


</div>

Any clue as to how to modify this to get the element?

Upvotes: 0

Views: 1936

Answers (1)

Quentin
Quentin

Reputation: 944443

load expects to receive a function as an argument.

showNewcontents() calls a function.

You are passing the return value of the call to showNewcontents, not the showNewcontents function.

Remove the ().

Upvotes: 2

Related Questions