Skip to content Skip to sidebar Skip to footer

Change Button Text In Meteor With Js

My button on click show and hide div that contains comment section. Now I want to make him to change text on click. So, you click once and you can see comments but instead of 'Show

Solution 1:

You shouldn't change HTML/CSS from JavaScript, instead handle that in your template.

Here's an example with untested code. It also relies on the package reactive-var.

<template name="t">
  <button id="b">{{#if isButtonActive}}Active!{{else}}Not active{{/if}}</button>
</template>
Template.t.onCreated(function(){
  this.isButtonActiveReactiveVar = newReactiveVar(false)
})

Template.t.helpers({
  'isButtonActive': function(){
    returnTemplate.instance().isButtonActiveReactiveVar.get()
  }
})

Template.t.events({
  'click #b': function(event, template){
    template.isButtonActiveReactiveVar.set(!template.isButtonActiveReactiveVar.get())
  }
})

Post a Comment for "Change Button Text In Meteor With Js"