What's the correct way to perform DOM manipulation in Meteor?
Asked Answered
M

3

2

I'm using a package called Timeline

https://github.com/VeriteCo/TimelineJS

It works by having a placeholder such as

<div id="my-timeline"></div>

And then ultimately making a jQuery call to manipulate the div. Visually I'm seeing the timeline appear on the screen and then disappearing almost straight away. A similar effect occurs with the following simple example:

<div id="my-temp"></div> 

combined with

$(document).ready(function() {
    $('#my-temp').html('HELLO');
});

What's the correct way to perform this type of manipulation without having the resultant HTML disappear?

Moria answered 25/10, 2012 at 1:3 Comment(0)
P
5

I believe you should use constant regions to prevent Meteor from re-rendering your div.

{{#constant}}
    <div id="my-temp"></div> 
{{/constant}}
Poorhouse answered 28/10, 2012 at 0:30 Comment(0)
K
2

Use Handlebars template, don't use jQuery's dom manipulation. If you have to use javascript dom manipulation, make sure to use Meteor.render().

http://docs.meteor.com/#meteor_render

Also you need to call your timeline creation code inside Template.myTemplate.rendered

http://docs.meteor.com/#template_rendered

Kosiur answered 25/10, 2012 at 5:57 Comment(1)
What if it's a third party library doing the DOM manipulation? Does that render the library incompatible?Moria
D
0

Meteor Render is the right way to go as mentioned by Harry. Here's the link to the new documentation http://blazejs.org/api/templates.html#Template-onRendered

Dehydrate answered 1/12, 2017 at 14:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.