Hello-World
Hello-World

Reputation: 9555

handlebars.js example jquery error

Can you please tell me why this handlebars.js example will not work? I get a jquery error?

TypeError: e is null in the jquery

looks like its happening here $(document).append(theTemplate(theData));

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script src="js/jquery-1.9.1.min.js"></script>
    <script src="js/handlebars.js"></script>

    <script type ="text/javascript">

        $(document).ready(function () {
            var theData = { headerTitle: 'Shop Page', weekDay: 'Wednesday' };
            var theTemplateScript = $("#header").html();
            var theTemplate = Handlebars.compile(theTemplateScript);
            $(document).append(theTemplate(theData));
        });
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <script id="header" type="text/x-handlebars-template">
        <div> {{ headerTitle }} </div>
        Today is {{weekDay}}
   </script>
   </div>
   </form>
</body>
</html>

Upvotes: 1

Views: 1020

Answers (2)

Parham
Parham

Reputation: 1067

I changed my jQuery version to 1.7.2 and it fixed the problem. still not sure what changed in the newer version

Upvotes: 1

Hello-World
Hello-World

Reputation: 9555

looks like the issue was appending to document if I change it to body it worked.

$('body').append(theTemplate(theData));

Upvotes: 0

Related Questions