# Issue with Jquery in plugin component

**URL:** https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086
**Category:** Development
**Created:** [April 7, 2020, 5:06am UTC](https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086 "2020-04-07T05:06:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Luke\_Clancy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/luke_clancy/32/166703_2.png) [@Luke\_Clancy](https://meta.discourse.org/u/Luke_Clancy)
#### Post date: [April 7, 2020, 5:06am UTC](https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086/1 "2020-04-07T05:06:53Z")

</div>

Is jQuery automatically enabled for plugin components? Am I missing a setup step?

I am having issues with simply accessing the html DOM through jquery (with the end goal of jquery’s [autocomplete function](https://jqueryui.com/autocomplete/)). Here is an example of one of my attempts, attempting to retrieve the ID of an element using its id. It never finds the element. Its as if the javascript does not have a reference point.

```
---- in /src/plugins/test/assets/javascripts/discourse/components ----
---- element-main.js.es6 ----
import discourseComputed, { observes } from "discourse-common/utils/decorators";
import jQuery from 'jquery';

export default Ember.Component.extend({
  init() {
    this._super(...arguments);
    console.log("in the templates/components/element-main.js.es6");
    console.log(jQuery);
    const aaa = jQuery('#eleinp');
    console.log(aaa)
    console.log(aaa.attr('id'));
  }
});

---- in /src/plugins/test/assets/javascripts/discourse/templates/components ----
---- element-main.hbs ----
<p>element-main in temp</p>
<input id="eleinp" value="HAHAHA">

```

I tried this.element, (this.element), (this), $(), etc. as well.

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [April 7, 2020, 6:01am UTC](https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086/2 "2020-04-07T06:01:55Z")

</div>

init is too early in the lifecycle to apply jquery. Also you don’t need to import it. Lastly, You need to evaluate if you REALLY need to use it in the first place. If you need to use it, didInsertElement or didRender are the correct places to use it.

---

<div class="post-metadata">

### Author: ![Luke\_Clancy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/luke_clancy/32/166703_2.png) [@Luke\_Clancy](https://meta.discourse.org/u/Luke_Clancy)
#### Post date: [April 7, 2020, 10:12pm UTC](https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086/3 "2020-04-07T22:12:42Z")

</div>

Thank you! didRender() worked well, I also took out the redundant import statement. I am using jQuery as I have a custom search statement on input that does not mesh with the ‘datalist’ html element. This is as datalist only shows options when they explicitly contain a substring.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [April 7, 2020, 10:51pm UTC](https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086/4 "2020-04-07T22:51:45Z")

</div>

Try to avoid jQuery, it is going to be removed from Ember and thus Discourse within the next two years. Vanilla modern JS is sufficient.

---

<div class="post-metadata">

### Author: ![Luke\_Clancy](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/luke_clancy/32/166703_2.png) [@Luke\_Clancy](https://meta.discourse.org/u/Luke_Clancy)
#### Post date: [April 10, 2020, 8:06pm UTC](https://meta.discourse.org/t/issue-with-jquery-in-plugin-component/147086/5 "2020-04-10T20:06:28Z")

</div>

Thanks for the heads up, I’m looking at [Awesomplete](https://leaverou.github.io/awesomplete/#customization) instead of JQuery’s autocomplete now
