# node.isInPage

{% tabs %}
{% tab title="💾 程式" %}
:floppy\_disk: replit: [node.isInPage](https://replit.com/@pegasusroe/nodeisInPage#script.js)

```javascript
// 🔸 node.isInPage
Object.defineProperty(Node.prototype, 'isInPage', {
    get() { return document.body.contains(this) }
});
```
{% endtab %}

{% tab title="⭐️ 重點" %}
{% hint style="warning" %}
不管一個 [htmlelement](../../htmlelement "mention") 是 display:none、visibility:hidden、opacity:0 等等，只要它在 [..](../../.. "mention") 裡面，<mark style="color:blue;">`node.isInPage`</mark> 就是 <mark style="color:yellow;">**true**</mark>。
{% endhint %}

```
CSS/JS/HTML              visible  space  clickable
---------------------------------------------------
CSS    opacity: 0            ❌    ✅    ✅
CSS    visibility: hidden    ❌    ✅    ❌
CSS    display: none         ❌    ❌    ❌
JS     .hidden = false       ❌    ❌    ❌
HTML   <... hidden>          ❌    ❌    ❌
```
{% endtab %}

{% tab title="📘 手冊" %}
* [..](.. "mention") ⟩ [.contains()](https://developer.mozilla.org/en-US/docs/Web/API/Node/contains) - check if a node is a descendant of a given node. (<mark style="color:yellow;">**itself**</mark> <mark style="color:orange;">**included**</mark>)
* [htmlelement](../../htmlelement "mention") ⟩ [.hidden](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden) - <mark style="color:red;">**quite different**</mark> from using CSS [`display`](https://developer.mozilla.org/en-US/docs/Web/CSS/display).
* [html](../../../../../html "mention") ⟩ [Global attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes) ⟩ [hidden](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden)
* [css](../../../../../css "mention") ⟩&#x20;
  * [display](https://developer.mozilla.org/en-US/docs/Web/CSS/display)
  * [visibility](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility)
  * [opacity](https://developer.mozilla.org/en-US/docs/Web/CSS/opacity)
{% endtab %}

{% tab title="📗 參考" %}
* [ ] CSSTrick ⟩ [The `hidden` Attribute is Visibly Weak](https://css-tricks.com/the-hidden-attribute-is-visibly-weak/)
* [ ] [The HTML Hidden Attribute Explained](https://www.semrush.com/blog/html-hide-element/)
* [ ] [【英文介係詞】該如何用英文表達「位置」？in front of/behind/next to/on/in/above….英文用法解說！](https://tw.englisher.info/2017/01/06/english-grammar-prepositions-of-place/)
{% endtab %}

{% tab title="🗣 討論" %}
* [How can I check if an element exists in the visible DOM?](https://stackoverflow.com/a/5629730/5409815)
* [What is the difference between visibility:hidden and display:none?](https://stackoverflow.com/a/133064/5409815)
* [what is the difference between opacity:0 and display:none?](https://stackoverflow.com/a/8598999/5409815)
* [What is the difference between the hidden attribute (HTML5) and the display:none rule (CSS)?](https://stackoverflow.com/questions/6708247/what-is-the-difference-between-the-hidden-attribute-html5-and-the-displaynone)
{% endtab %}

{% tab title="❓" %}
{% hint style="warning" %}
問：「HTML [hidden](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden) attribute is equivalent to [HTMLElement.hidden](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/hidden) property❓」
{% endhint %}
{% endtab %}
{% endtabs %}
