Skip to content

Commit

Permalink
Added initialization using a CSS string selector or an HTMLElement ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
ZsharE committed Aug 28, 2024
1 parent d61449e commit b512e30
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,15 @@ A simple and easy JavaScript library for highlighting .NET stack traces
[Stack Trace Formatter - Online pretty print of .NET stack traces](https://elmah.io/tools/stack-trace-formatter/)

#### Initialization
Using a string that represents a CSS selector:
```javascript
const stack = new netStack('.stacktrace');
```
Passing an HTMLElement object:
```javascript
const stackElement = document.querySelector('.stacktrace');
const stack = new netStack(stackElement);
```

#### Default values for classes
```javascript
Expand Down
8 changes: 7 additions & 1 deletion netstack.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@

function netStack(element, options) {
if (typeof document !== 'undefined') {
this.element = document.querySelector(element);
if (typeof element === 'string') {
this.element = document.querySelector(element);
} else if (element instanceof HTMLElement) {
this.element = element;
} else {
throw new Error('The element parameter must be a selector string or an HTMLElement.');
}
} else {
throw new Error('netStack requires a DOM environment');
}
Expand Down

0 comments on commit b512e30

Please sign in to comment.