Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ There are a few more advanced methods to how the Html class works:
new Html("span").classOff("my-class");
// <span></span>
```
- `.id()`
Set the id of an element
```js
new Html("div").id("my-id");
// <div id="my-id"></div>
```
- `.on(eventName, eventHandler)`
Add an event listener

Expand Down Expand Up @@ -299,6 +305,22 @@ There are a few more advanced methods to how the Html class works:
input.getValue(); // 'I typed this text'
```

## Building

Clone the repository:

```
git clone https://github.com/datkat21/html.git
cd html
```

Install dependencies and run build script:

```
npm i
npm run build # Build script.
```

## Repository

You can find the repository [on GitHub.](https://github.com/datkat21/html)
6 changes: 6 additions & 0 deletions dist/html.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ export default class Html {
* @returns The HTML element (as Html)
*/
queryHtml(selector: string): Html | null;
/**
* Sets the ID of the element.
* @param val The ID to set.
* @returns Html
*/
id(val: string): Html;
/**
* Toggle on/off a class.
* @param val The class to toggle.
Expand Down
12 changes: 12 additions & 0 deletions dist/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ export default class Html {
queryHtml(selector) {
return new Html(this.elm.querySelector(selector));
}
/**
* Sets the ID of the element.
* @param val The ID to set.
* @returns Html
*/
id(val) {
if (this.elm.id != null) {
throw Error("The element already has an ID.");
}
this.elm.id = val;
return this;
}
/**
* Toggle on/off a class.
* @param val The class to toggle.
Expand Down
3 changes: 2 additions & 1 deletion build.js → format.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ const result = await format(compiledJsContent, {
filepath: compiledJsPath
});

fs.writeFileSync(compiledJsPath, result);
fs.writeFileSync(compiledJsPath, result);
console.log(`Formatting (and building) complete. Wrote to ${compiledJsPath}`)
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"author": "datkat21",
"license": "ISC",
"scripts": {
"build": "npx tsc && node build.js"
"build": "npx tsc && node format.js"
},
"repository": {
"type": "git",
Expand Down
12 changes: 12 additions & 0 deletions src/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ export default class Html {
queryHtml(selector: string): Html | null {
return new Html(this.elm.querySelector(selector) as HTMLElement);
}
/**
* Sets the ID of the element.
* @param val The ID to set.
* @returns Html
*/
id(val: string): Html {
if(this.elm.id != null) {
throw Error("The element already has an ID.");
}
this.elm.id = val;
return this;
}
/**
* Toggle on/off a class.
* @param val The class to toggle.
Expand Down