How to initialize a jQuery object after rendering the layout?

I would like to define a few variables that I use to span jQuery selectors later after the application layout has been displayed.

I tried to define them with:

Meteor.startup(function () { /* Define variables */ })

But it didn’t work, the objects were empty

Here's how I declare my application layout:

Router.configure({
  layoutTemplate: 'layout'
});

Here is the layout itself:

<template name="layout">
  <div id="page_container">
    <header id="page_header">
    </header>

    <div id="page_content">
      {{> yield}}
    </div>
  </div>
</template>

Here are the variables that I want to declare:

  L.BODY = $("body");
  L.PC   = $("#page_content", L.BODY);

The declaration itself works great, but L.BODYshows that the body of my application is still empty by the time I try to declare these variables.

How can I define jQuery objects after displaying the layout of my application?

+4
source share
1 answer

layout - . jQuery DOM .

onRendered - :

Template.layout.onRendered(function() {
  L.BODY = $('body');
  L.PC   = $('#page_content', L.BODY);
});
+6

Source: https://habr.com/ru/post/1607160/


All Articles