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
Copy file name to clipboardExpand all lines: README.md
+39-1Lines changed: 39 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -193,7 +193,7 @@ All of the following strings are valid wrapper definitions
193
193
* `<div class='wrapper' id="container"></div>`
194
194
195
195
### Element Insertions
196
-
By using `before`, `after`, `prepend` and `append` you can control where to insert newly created elements.
196
+
By using `before`, `after`, `prepend` and `append` you can control where to insert newly created elements. Also with `replaceWith` you can swap the element with a new one.
197
197
198
198
``` js
199
199
let el =uxr('.container');
@@ -213,8 +213,46 @@ el.append(uxr('#new'));
213
213
// appends an element add the beginning of selection's content
214
214
el.prepend('<p>This will before "el"</p>');
215
215
el.prepend(uxr('#new'));
216
+
217
+
// replaces the element with new one
218
+
el.replaceWith('<div id="replaced">Previous element replaced</div>');
216
219
```
217
220
221
+
### Traversing
222
+
With traversal methods, you can find adjacent or parent elements accordingly. Almost all traversal methods returns a `uxr` object. You can return the previous `uxr` by chaining `end()`
223
+
224
+
```javascript
225
+
226
+
let el =uxr('li');
227
+
228
+
// get the immediate parent
229
+
el.closest();
230
+
231
+
// get the grandparent
232
+
el.closest().closest();
233
+
234
+
// filter the parents and get the first matched
235
+
el.closest(selector);
236
+
237
+
// get the next sibling
238
+
el.next();
239
+
240
+
// get the next sibling if matched
241
+
el.next(selector);
242
+
243
+
// get the previous sibling
244
+
el.prev();
245
+
246
+
// get the previous sibling if matched
247
+
el.prev(selector);
248
+
249
+
// get the first element in uxr object - selection
0 commit comments