jQuery function doesn´t execute after filter rendered

3 views
Skip to first unread message

egentil...@gmail.com

unread,
Oct 26, 2016, 7:00:35 PM10/26/16
to JavaScript Templates Engine PURE
Hi.
I have a jQuery effect over a material card. Clicking a link it add a class.
It works the first time, but after filtering it doesn´t work.
I'm new to js that`s for sure the issue.
I think it's related to scope or something like that.

could anybody help?
thanks

Mic (BeeBole)

unread,
Oct 26, 2016, 7:17:26 PM10/26/16
to JavaScript Templates Engine PURE
Either you must reattach the click event to the node after each render.
The nodes are replaced by new ones, so your click attachment is gone.

Or you add a directive that will call a function based on the onclick event.
eg: '.material-card > .mc-btn-action@onclick': function(a){
  //call here what you want to do at the click event
}

In our app, I use mainly the later option.

One remark, since you are new to JS.
I'm not sure why you needed to use setTimeout's in your click function. 
But it is probably a patch over an issue that should have been fixed upstream :)

You should never rely on a timeout, to be sure something was done before an action.
If that something lasts more than 800 ms it will fail.

Ezequiel Gentile Montes

unread,
Oct 27, 2016, 7:52:13 PM10/27/16
to JavaScript Templates Engine PURE
Oh that was quick!
following your tip...
this do de thing
  $('.container').on('click', '.material-card > .mc-btn-action', function () { 
thanks
Reply all
Reply to author
Forward
0 new messages