Skip to content

Commit eb8927b

Browse files
committed
Added missing documentation.
1 parent a9ff034 commit eb8927b

9 files changed

Lines changed: 408 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# .insertBefore()
2+
Add nodes before each object in a Dabby collection.
3+
4+
# .prependTo()
5+
Prepend nodes to each object in a Dabby collection.
6+
7+
# .appendTo()
8+
Append nodes to each object in a Dabby collection.
9+
10+
# .insertAfter()
11+
Add nodes after each object in a Dabby collection.
12+
13+
## Usage
14+
```javascript
15+
$(content).insertBefore(selector);
16+
$(content).prependTo(selector);
17+
$(content).appendTo(selector);
18+
$(content).insertAfter(selector);
19+
```
20+
21+
### content
22+
The Dabby collection, node, array of nodes, or document to insert.
23+
24+
### selector
25+
A string specifying a CSS selector, a node, an array of nodes, a document, or a Dabby collection to attach the Dabby collection to.
26+
27+
## Returns
28+
The original Dabby collection.
29+
30+
## Differences to jQuery
31+
None.
32+
33+
## Examples
34+
35+
### Using .insertBefore()
36+
This will insert the `<span>` element before the` <p>` element.
37+
38+
```javascript
39+
$("<span>Hello</span>").insertBefore("p.target");
40+
```
41+
42+
### Using .prependTo()
43+
This will prepend the `<h2>` element to the `<section>` element.
44+
45+
```javascript
46+
$("<h2>My Title</h2>").prependTo("section.main");
47+
```
48+
49+
### Using .appendTo()
50+
This will append the `<li>` element to the `<ul>` element.
51+
52+
```javascript
53+
$("<li>Item 3</li>").appendTo("ul#my-list");
54+
```
55+
56+
### Using .insertAfter()
57+
This will insert the `<button>` element after the `<div>` element.
58+
59+
```javascript
60+
$("<button>Click Me</button>").insertAfter("div#container");
61+
```

src/manipulation/remove/readme.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# .detach()
2+
Detaches some or all of the items in the collection from the DOM. This method is similar to .remove(), except it keeps all data and events associated with the detached elements. This is useful if you want to reinsert the elements into the DOM later.
3+
4+
## Usage
5+
```javascript
6+
$(selector).detach();
7+
$(selector).detach(selector);
8+
```
9+
10+
### selector
11+
A optional selector, HTML string, Node, array of Nodes, Dabby collection or a callback function to filter the collection by.
12+
13+
## Returns
14+
A new Dabby collection containing the detached nodes.
15+
16+
## Differences to jQuery
17+
None.
18+
19+
## Examples
20+
Detach all `<li>` elements from a `<ul>`, this will remove all list items from the `<ul>` and store them in a variable:
21+
22+
```javascript
23+
const items = $("ul#my-list li").detach();
24+
```
25+
26+
Detach a specific `<div>` with a filter, this will detach any `<p>` elements that are children of `#my-div`:
27+
28+
```javascript
29+
const items = $("div#my-div p").detach("p");
30+
```
31+
32+
# .remove()
33+
Removes some or all of the items in the collection from the DOM. This method removes the selected elements and all of their associated data and events.
34+
35+
## Usage
36+
```javascript
37+
$(collection).remove();
38+
$(collection).remove(selector);
39+
```
40+
41+
### selector
42+
A optional selector, HTML string, Node, array of Nodes, Dabby collection or a callback function to filter the collection by.
43+
44+
## Returns
45+
The original Dabby collection.
46+
47+
## Differences to jQuery
48+
None.
49+
50+
## Examples
51+
Remove a button from the page, this will completely remove the button and its associated data from the page:
52+
53+
```javascript
54+
$("button#my-button").remove();
55+
```
56+
57+
Remove specific `<li>` elements, this will remove any list items with the class completed:
58+
59+
```javascript
60+
$("ul#my-list li").remove(".completed");
61+
```

src/manipulation/replace/readme.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# .replaceAll()
2+
Replaces all elements matched by a selector with the elements in the current Dabby collection. This method is the reverse of `.replaceWith()`.
3+
4+
## Usage
5+
```javascript
6+
$(content).replaceAll(selector);
7+
```
8+
9+
### selector
10+
A selector string, Node, array of Nodes, Dabby collection or a callback function.
11+
12+
### content
13+
An HTML string, Node, array of Nodes, or a Dabby collection.
14+
15+
## Returns
16+
The original Dabby collection.
17+
18+
## Differences to jQuery
19+
None.
20+
21+
## Examples
22+
This will replace all `<h2>` elements with the `<p>` element.
23+
24+
```javascript
25+
$("<p>A new paragraph</p>").replaceAll("h2");
26+
```
27+
28+
# .replaceWith()
29+
Replaces each element in the current Dabby collection with the provided new elements.
30+
31+
## Usage
32+
```javascript
33+
$(selector).replaceWith(content);
34+
```
35+
36+
### selector
37+
A selector string, Node, array of Nodes, Dabby collection or a callback function.
38+
39+
### content
40+
An HTML string, Node, array of Nodes, or a Dabby collection.
41+
42+
## Returns
43+
The original Dabby collection.
44+
45+
## Differences to jQuery
46+
None.
47+
48+
## Examples
49+
This will replace each `.item` div with a new `<li>` element:
50+
51+
```javascript
52+
$(".item").replaceWith("<li>New List Item</li>");
53+
```

src/manipulation/text/readme.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# .text()
2+
Retrieves the text from all items in the collection, or sets the text content on each item in the collection.
3+
4+
## Usage
5+
```javascript
6+
$(selector).text();
7+
$(selector).text(text);
8+
```
9+
10+
### text
11+
A string of text, or a function that returns a string.
12+
13+
## Returns
14+
When getting text: A string containing the combined text of all elements in the collection.
15+
16+
When setting text: The original Dabby collection.
17+
18+
## Differences to jQuery
19+
None.
20+
21+
## Examples
22+
This will retrieve the text content of the `<p>` element:
23+
24+
```javascript
25+
const myText = $("p").text();
26+
console.log(myText);
27+
```
28+
29+
This will set the text content of the `<h2>` element to "New Title".
30+
31+
```javascript
32+
$("h2").text("New Title");
33+
```
34+
35+
Set the text using a function, this will set the text of each `<li>` element to include its index and its original text.
36+
37+
```javascript
38+
$("li").text((i, value) => "Item " + (i + 1) + ": " + value);
39+
```

src/manipulation/unwrap/readme.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# .unwrap()
2+
Removes the parents of some or all of the items in the collection, leaving the children in their place.
3+
4+
## Usage
5+
```javascript
6+
$(collection).unwrap();
7+
$(collection).unwrap(selector);
8+
```
9+
10+
### selector
11+
An optional selector to match the parent element to be removed.
12+
13+
## Returns
14+
The original Dabby collection.
15+
16+
## Differences to jQuery
17+
None.
18+
19+
## Examples
20+
Unwrap all `<div>` elements, this will remove the `<div>` parent of all `p` tags with the target class, moving the `p` tags up one level in the DOM tree.
21+
22+
```javascript
23+
$("p.target").unwrap("div");
24+
```
25+
26+
Unwrap a specific element, this will unwrap the `<p>` element from its `<span>` parent, leaving the `<span>`'s content in its place.
27+
28+
```javascript
29+
$("p.my-paragraph").unwrap();
30+
```

src/manipulation/wrap/readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# .wrap()
2+
Wraps each element in the collection with the provided new elements.
3+
4+
## Usage
5+
```javascript
6+
$(selector).wrap(html);
7+
```
8+
9+
### html
10+
An HTML string, Node, array of Nodes, Dabby collection or a callback function.
11+
12+
## Returns
13+
The original Dabby collection.
14+
15+
## Differences to jQuery
16+
None.
17+
18+
## Examples
19+
Wrap a single element, this will wrap the `<p>` element with a `<div>` element:
20+
21+
```javascript
22+
// HTML before
23+
// <p>Hello, World!</p>
24+
25+
$("p").wrap("<div>");
26+
27+
// HTML after
28+
// <div><p>Hello, World!</p></div>
29+
```
30+
31+
Wrap multiple elements, this will wrap each `<li>` element with a `<div>` element:
32+
33+
```javascript
34+
// HTML before
35+
// <p>Item 1</p>
36+
// <p>Item 2</p>
37+
// <p>Item 3</p>
38+
39+
const div = $("<div>", {"class": "wrap"});
40+
$("p").wrap(div); // will be cloned for each item that is wrapped
41+
42+
// HTML after
43+
// <div class="wrap"><p>Item 1</p></div>
44+
// <div class="wrap"><p>Item 2</p></div>
45+
// <div class="wrap"><p>Item 3</p></div>
46+
```

src/manipulation/wrapall/readme.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# .wrapAll()
2+
Wraps all elements in the collection with the provided new elements. Unlike .wrap(), this method wraps all elements with a single element, rather than wrapping each element individually.
3+
4+
## Usage
5+
```javascript
6+
$(selector).wrapAll(html);
7+
```
8+
9+
### html
10+
An HTML string, Node, array of Nodes, Dabby collection or a callback function.
11+
12+
## Returns
13+
The original Dabby collection.
14+
15+
## Differences to jQuery
16+
None.
17+
18+
## Examples
19+
This will wrap all `<h2>` and `<p>` elements with a `<div>` element:
20+
21+
```javascript
22+
// HTML before
23+
// <h2>Item 1</h2>
24+
// <p>Item 2</p>
25+
// <p>Item 3</p>
26+
27+
$("h2, p").wrapAll("<div>");
28+
29+
// HTML after
30+
// <div>
31+
// <h2>Item 1</h2>
32+
// <p>Item 2</p>
33+
// <p>Item 3</p>
34+
// </div>
35+
```

src/utils/isplainobject/readme.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# $.isPlainObject()
2+
Tests a value to see if it is a plain object, that was defined with {} and has a prototype of Object.
3+
4+
## Usage
5+
```javascript
6+
$.isPlainObject(obj);
7+
```
8+
9+
### obj
10+
The value to be tested.
11+
12+
## Returns
13+
A boolean indicating whether the input value is a plain object.
14+
15+
## Differences to jQuery
16+
None.
17+
18+
## Examples
19+
This will return `true` because the object was created using object literal notation:
20+
21+
```javascript
22+
const myObject = {};
23+
console.log($.isPlainObject(myObject));
24+
// Expected output: true
25+
```
26+
27+
This will return `false` because an array's prototype is `Array`, not `Object`:
28+
29+
```javascript
30+
const myArray = [];
31+
console.log($.isPlainObject(myArray));
32+
// Expected output: false
33+
```
34+
35+
This will return `false` because a `Date` object's prototype is `Date`:
36+
37+
```javascript
38+
const myDate = new Date();
39+
console.log($.isPlainObject(myDate));
40+
// Expected output: false
41+
```

0 commit comments

Comments
 (0)