Skip to content

Commit b512e30

Browse files
committed
Added initialization using a CSS string selector or an HTMLElement object
1 parent d61449e commit b512e30

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,15 @@ A simple and easy JavaScript library for highlighting .NET stack traces
1515
[Stack Trace Formatter - Online pretty print of .NET stack traces](https://elmah.io/tools/stack-trace-formatter/)
1616

1717
#### Initialization
18+
Using a string that represents a CSS selector:
1819
```javascript
1920
const stack = new netStack('.stacktrace');
2021
```
22+
Passing an HTMLElement object:
23+
```javascript
24+
const stackElement = document.querySelector('.stacktrace');
25+
const stack = new netStack(stackElement);
26+
```
2127

2228
#### Default values for classes
2329
```javascript

netstack.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,13 @@
2020

2121
function netStack(element, options) {
2222
if (typeof document !== 'undefined') {
23-
this.element = document.querySelector(element);
23+
if (typeof element === 'string') {
24+
this.element = document.querySelector(element);
25+
} else if (element instanceof HTMLElement) {
26+
this.element = element;
27+
} else {
28+
throw new Error('The element parameter must be a selector string or an HTMLElement.');
29+
}
2430
} else {
2531
throw new Error('netStack requires a DOM environment');
2632
}

0 commit comments

Comments
 (0)