user441222
user441222

Reputation: 2001

load part of a page with jquery

There are two pages ,Add part of webform4.html's page content into webform3.html's div after webform3.html load completed.But when I click the Buttone4,the event do not work. How to fix this?Thank you very much!

WebForm3.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<script src="scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $("#W4").load("WebForm4.html #CC");
        $("#Button4").click(function () {
            alert("webform4.html");
        })
    })
</script>
</head>
<body>
<form>
<div id="W4">
</div>
<input id="Button1" type="button" value="button" />
</form>
</body>
</html>

WebForm4.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<div id="CC">
    <input id="Button4" type="button" value="button"/>
</div>
</body>
</html>

Upvotes: 0

Views: 438

Answers (2)

Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100175

try using .on instead of just .click:

$(function () {
    $("#W4").load("WebForm4.html #CC");
    $("#Button4").on("click", function () {
        alert("webform4.html");
    });
});

Upvotes: 0

Konstantin Dinev
Konstantin Dinev

Reputation: 34895

Attach your event handler with delegate() or attach it after the load is complete in the callback:

<script type="text/javascript">
    $(function () {
        $("#W4").load("WebForm4.html #CC", function () {
            $("#Button4").click(function () {
                alert("webform4.html");
            });
        });
    })
</script>

Upvotes: 1

Related Questions