JavaScript on jQuery created code never gets called

Posted by mare on Stack Overflow See other posts from Stack Overflow or by mare
Published on 2010-03-23T15:51:15Z Indexed on 2010/03/23 15:53 UTC
Read the original article Hit count: 308

Filed under:
|
|

This is my view in ASP.NET MVC.

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Administration.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">

        var ddlContentTypes;

        $(document).ready(function () {
            ddlContentTypes = $("#ContentTypes");
            ddlContentTypes.bind("change", loadCreate);
            loadCreate();
        });

        function loadCreate() {
            var typeId = $("#ContentTypes option:selected").val();
            $.get('~/' + typeId + '/Create', function (data) {
                $("#CreateForm").html(data);
            });
            $("fieldset input").each(function (index, item) {
                $(item).attr("disabled", true);
            });
        }
    </script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        <%=Resources.Localize.CreateWidget %></h2>
    <p>
        <% Html.RenderPartial("ContentTypeSelector"); %></p>
    <div id="CreateForm">
    </div>
</asp:Content>

As you can see, it loads some HTML (actually user control) and adds it to the CreateForm div. This actually works fine.

The problem is this

$("fieldset input").each(function (index, item) {
                $(item).attr("disabled", true);
            });

never runs. The fieldset tag is in the response, so you don't see it here but it's there - everything is returned back fine (I checked with Firebug).

Why do the above two lines of JS never run or have any effect?

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about JavaScript