Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixcai/is-html-object
Check if referenced object is a DOM element or Browser Object
https://github.com/pixcai/is-html-object
Last synced: 26 days ago
JSON representation
Check if referenced object is a DOM element or Browser Object
- Host: GitHub
- URL: https://github.com/pixcai/is-html-object
- Owner: pixcai
- License: mit
- Created: 2016-08-29T07:50:13.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-29T13:24:16.000Z (about 8 years ago)
- Last Synced: 2024-09-14T20:59:47.068Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# is-html-object
Check if referenced object is a DOM element or Browser Object[![npm](https://img.shields.io/npm/v/is-html-object.svg?style=flat-square)](https://www.npmjs.com/package/is-html-object)
[![npm](https://img.shields.io/npm/dt/is-html-object.svg?style=flat-square)](https://www.npmjs.com/package/is-html-object)
[![npm](https://img.shields.io/npm/l/is-html-object.svg?style=flat-square)](https://www.npmjs.com/package/is-html-object)## Install
```shell
npm install --save is-html-object
```## API
### isHtmlObject(el|selector)
Check if `el` or `selector` is a DOM element or Browser ObjectIt's equivalent
```js
isHtmlObject.htmlElement(el|selector) || isHtmlObject.browserObject(el|selector)
```
Example:
```js
// Pass a selector string
if (isHtmlObject('#root')) {
// is valid DOM element
}
// Pass a DOM element
if (isHtmlObject(document.getElementById('root'))) {
// is valid DOM element
}
```### browserObject(el|selector)
Check if `el` or `selector` is an Browser ObjectBrowser Object includes `window`, `screen`, `document`, `navigator`, `history`, `location`
Example:
```js
if (isHtmlObject.browserObject(window)) {
// is window object
}
// Check if `el` or `selector` is an certain object
if (isHtmlObject.screen(screen)) {
// is screen object
}
```### htmlElement(el|selector)
Check if `el` or `selector` is a DOM elementExample:
```js
console.log(isHtmlObject.htmlElement(window)) // false
console.log(isHtmlObject.htmlElement('body')) // true
```### Others
Check if `el` or `selector` is an certain object
```js
if (isHtmlObject.screen(screen)) {
// is screen object
}if (isHtmlObject.body(document.body)) {
// is body element
}if (isHtmlObject.anchor(document.querySelector('a'))) {
// is anchor element
}if (isHtmlObject.div('#root')) {
// is div element
}
```## Usage
```js
var isHtmlObject = require('is-html-object');// Pass a selector string
if (isHtmlObject('#root')) {
// is valid DOM element
}if (isHtmlObject.htmlElement('#root')) {
// is valid DOM element
}// Pass a DOM element
if (isHtmlObject(document.getElementById('root'))) {
// is valid DOM element
}console.log(isHtmlObject(window)) // true
console.log(isHtmlObject.browserObject(window)) //true
console.log(isHtmlObject.screen(screen)) // true
console.log(isHtmlObject.window(document)) // false
console.log(isHtmlObject.anchor(document.querySelector('a'))) // true
console.log(isHtmlObject.paragraph('p')) // trueif (isHtmlObject.div('#root')) {
// is div element
}
```## License
MIT