What is the meteor way to get inner-html from a rendered element?


#1

hello world,

I am new to meteor.
Today I am using meteor 1.0.5

I want to learn how to get inner-html from a rendered element.

I know how to do this using jquery.

I want to learn how to do it the meteor way.

I have a template named t2.html

In it I have a pre-element with id set to ‘id1’.

Inside the pre-element I have some text.

I verified that meteor can serve t2.html.

Next I created t2.js and put this syntax in it:

if (Meteor.isClient) {
  Template.t2.onRendered(function() {
    var myelem = this.find("id1");
    var xyz = 1.1; });}

I think my call to this.find() is failing.

According to the js-console in my browser,
myelem stays null.

Question:

What is the meteor way to get inner-html from a rendered element?


#2

Selectors to template.find in Meteor works just as they do in jQuery. So you should have this.find("#id1") to search for the id id1.

Meteor does not provide a way to retrieve the content of an element, so you must use the DOM (possibly via jQuery).


#3

I figured this out:

I need to use a proper CSS selector: #id1 instead of id1.


#4

Which just so happens to be what @Peppe_LG suggested about 15 hours ago.