I am trying to use jquery like this in meteor.js app.
JS:
if (Meteor.isClient) {
Meteor.startup(function() {
$( "button" ).click(function() {
$( "p" ).toggle();
});
});
...
Or without meteor.startup function. Neither works.
HTML:
<button>Click</button>
<p>Can you see me?</p>
I get no errors and nothing happens when I click the button.
You shouldn't use jQuery for simple event handling like this, use Meteor templates event maps instead :
HTML :
<template name="myTemplate">
<button type="button">Click me !</button>
<p>Can you see me ?</p>
</template>
JS :
Template.myTemplate.events({
"click button":function(event, template){
template.$("p").toggle();
}
});
use meteor list
to see if jquery package has included.
if not, use meteor add jquery
to add the package
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With