# When this.$() returns null

**URL:** <https://discuss.emberjs.com/t/when-this-returns-null/3397>\
**Category:** Uncategorized\
**Created:** [November 20, 2013, 4:37pm UTC](https://discuss.emberjs.com/t/when-this-returns-null/3397 "2013-11-20T16:37:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![TMQuinn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tmquinn/32/4790_2.png) [@TMQuinn](https://discuss.emberjs.com/u/TMQuinn)\
**Post date:** [November 20, 2013, 4:37pm UTC](https://discuss.emberjs.com/t/when-this-returns-null/3397/1 "2013-11-20T16:37:51Z")

</div>

I’ve been doing some work in an implementation of View#didInsertElement in Ember 1.1.2 and am noticing that invoking this.$(‘.foo’) returns undefined if there is no element of class foo. However, jQuery returns an empty Array in this case. Is this intentional or a bug?

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [November 20, 2013, 5:04pm UTC](https://discuss.emberjs.com/t/when-this-returns-null/3397/2 "2013-11-20T17:04:16Z")

</div>

how about `Ember.$('.foo')`?

---

<div class="post-metadata">

**Author:** ![TMQuinn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tmquinn/32/4790_2.png) [@TMQuinn](https://discuss.emberjs.com/u/TMQuinn)\
**Post date:** [November 20, 2013, 5:18pm UTC](https://discuss.emberjs.com/t/when-this-returns-null/3397/3 "2013-11-20T17:18:02Z")

</div>

Hmm… haven’t checked that yet. But the idea is that this.$() will give me the jQuery element for that view, then I can essentially do a .find(‘.foo’) by just calling this.$(‘.foo’), but it should never return undefined.

---

<div class="post-metadata">

**Author:** ![jasonmit](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/jasonmit/32/182_2.png) [@jasonmit](https://discuss.emberjs.com/u/jasonmit)\
**Post date:** [November 20, 2013, 6:49pm UTC](https://discuss.emberjs.com/t/when-this-returns-null/3397/4 "2013-11-20T18:49:35Z")

</div>

But here is a jsfiddle that I think displays that it is working [Ember Latest - JSFiddle - Code Playground](http://jsfiddle.net/NQKvy/378/)

Just make sure your markup is correct, because I’ve seen scenarios where that breaks the traversing.

---

<div class="post-metadata">

**Author:** ![TMQuinn](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/tmquinn/32/4790_2.png) [@TMQuinn](https://discuss.emberjs.com/u/TMQuinn)\
**Post date:** [November 20, 2013, 7:08pm UTC](https://discuss.emberjs.com/t/when-this-returns-null/3397/5 "2013-11-20T19:08:50Z")

</div>

Hmmm… let me reduce my case down and see if it still shows…
