2013-02-03 31 views
1

在一个干净的流星应用程序中添加了jquery包,我试图使用基本的jQuery css选择器。我究竟做错了什么?非工作示例可在此处找到:http://jquery-test.meteor.com/MeteorJS基本的jQuery使用

JavaScript直接放置在生成的template.hello.events方法的下方。

JS:

$("#foo").click(function() { 
console.log("clicked!"); 
}); 

HTML:

<button id="foo" style="border: 10px">This is a test div</button> 

回答

2

你必须把Template.hello.rendered函数内部的jQuery代码。

+0

因此,为了清楚起见:Meteor动态生成html元素。这意味着我需要将我的jQuery代码放置在确保元素已经被渲染的位置。 – Sam

+1

是的,在启动时,Meteor将整个应用程序中整个.html文件中的所有