Note that there are some explanatory texts on larger screens.

plurals
  1. POQuerying over DOM inside the handler of an event
    primarykey
    data
    text
    <p>I'm using DOJO to create some animations. I'm trying to animate an <code>h1</code> inside a section when the mouse is hovering the section.</p> <p><strong>This does work:</strong></p> <p>HTML:</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojo/dojo.js" data-dojo-config="async: true, isDebug: true"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="section"&gt; &lt;div id="title"&gt;Something&lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>JavaScript:</p> <pre class="lang-js prettyprint-override"><code>require(["dojo/fx", "dojo/on", "dojo/dom", "dojo/mouse","dojo/query","dojo/domReady!"], function(fx, on, dom, mouse,query) { var section = dom.byId("section"), title = dom.byId("title"); on(section, mouse.enter, function(evt){ fx.slideTo({ node: title, top: "0" }).play(); }); on(section, mouse.leave, function(evt){ fx.slideTo({ node: title, top: "200" }).play(); }); }); </code></pre> <p><strong>What I'd like to get working (It doesn't):</strong></p> <p>HTML:</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;script src="//ajax.googleapis.com/ajax/libs/dojo/1.8.0/dojo/dojo.js" data-dojo-config="async: true, isDebug: true"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="script.js"&gt;&lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;section&gt; &lt;h1&gt;Something&lt;/h1&gt; &lt;/section&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>JavaScript:</p> <pre class="lang-js prettyprint-override"><code>require(["dojo/fx", "dojo/on", "dojo/dom", "dojo/mouse","dojo/query","dojo/domReady!"], function(fx, on, dom, mouse,query) { var section = query("section"); on(section, mouse.enter, function(evt){ fx.slideTo({ node: query("h1",this), top: "0" }).play(); }); on(section, mouse.leave, function(evt){ fx.slideTo({ node: query("h1",this), top: "200" }).play(); }); }); </code></pre> <p>I'm trying to get the <code>h1</code> element, using <code>query("h1",this)</code>, to slide it. All I get is an error in my development tools. I have tried searching for a solution, but I'm unable to find one. How can I resolve this issue?</p> <pre><code> Uncaught TypeError: Object [object HTMLHeadingElement] has no method 'getBoundingClientRect' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload