Reputation: 4597
I just getting started with meteor so I want to use append function in jquery but it not append anything
JS:
if (Meteor.isClient) {
Meteor.startup(function() {
$( "span" ).append('Hello');
});
I get no errors and nothing happens or appending.
HTML:
<span>lorem ipsum</span>
<p>stackoverflow</p>
i think the problem is $('span').append('Hello');
it loading before the html code ??
Upvotes: 1
Views: 91
Reputation: 4820
Yes, Meteor needs to use its renderer's own hooks for "DOM readiness". If you use Blaze (Meteor's default renderer, as of now) you can use the Template.templateName.onRendered()
function for this:
Template.templateName.onRendered(function () {
$( "span" ).append('Hello');
});
This will append "Hello" to any span the template templateName
may contain.
Note that, as I implied earlier, this will be different depending on the renderer you choose for your app: Blaze, Angular or React. (or anything else for that matter) But the default one is Blaze, so if you do not know which one you are using, it is probably Blaze.
Upvotes: 3