You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 26, 2019. It is now read-only.
Copy file name to clipboardExpand all lines: source/components/the-component-lifecycle.md
+36-15Lines changed: 36 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,39 +123,54 @@ Ember guarantees that, by the time `didInsertElement()` is called:
123
123
1. The component's element has been both created and inserted into the
124
124
DOM.
125
125
2. The component's element is accessible via the component's
126
-
[`$()`][dollar]
127
-
method.
126
+
[`element`][element]
127
+
property.
128
128
129
-
A component's [`$()`][dollar] method allows you to access the component's DOM element by returning a JQuery element.
130
-
For example, you can set an attribute using jQuery's `attr()` method:
129
+
A component's [`element`][element] property allows you to access the component's DOM element.
130
+
For example, you can set a property:
131
131
132
132
```app/components/profile-editor.js
133
133
importComponentfrom'@ember/component';
134
134
135
135
exportdefaultComponent.extend({
136
136
didInsertElement() {
137
137
this._super(...arguments);
138
-
this.$().attr('contenteditable', true);
138
+
this.element.contentEditable='true';
139
139
}
140
140
});
141
141
```
142
142
143
-
[`$()`][dollar] will, by default, return a jQuery object for the component's root element, but you can also target child elements within the component's template by passing a selector:
143
+
[`element`][element] will return the component's root element,
144
+
but you can also target child elements within the component's template by using `querySelector`:
144
145
145
146
```app/components/profile-editor.js
146
147
importComponentfrom'@ember/component';
147
148
148
149
exportdefaultComponent.extend({
149
150
didInsertElement() {
150
151
this._super(...arguments);
151
-
this.$('div p button').addClass('enabled');
152
+
this.element.querySelector('div p button').classList.add('enabled');
152
153
}
153
154
});
154
155
```
155
156
156
157
Let's initialize our date picker by overriding the [`didInsertElement()`][did-insert-element] method.
157
158
158
-
Date picker libraries usually attach to an `<input>` element, so we will use jQuery to find an appropriate input within our component's template.
159
+
Date picker libraries usually attach to an `<input>` element, so we will look for an appropriate input within our component's template.
0 commit comments