diff --git a/docs/element-properties.mdx b/docs/element-properties.mdx index 1762383..a60cfe4 100644 --- a/docs/element-properties.mdx +++ b/docs/element-properties.mdx @@ -285,3 +285,95 @@ text.innerText = "new text \n and a newline"   + +### 7. innerHTML + +`Element.innerHTML: string [= value]` + +Returns the **html markup contained within the element** as a string. + +Can be set, to replace the **contents of the element with nodes parsed** from the given string. The existing content will be removed. + +:::note To insert instead of replace + +To **insert** the html into the element rather than replacing it, read about the method [`insertAdjacentHTML()`](https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML). + +::: + +**Example 1-** +```jsx +
+
text1
+
text2
+
+ +console.log(parent.innerHTML) +//
text1
+//
text2
+``` + +**Example 2-** +```jsx +
+ +parent.innerHTML = ` +
text1
+
text2
+` + +// result html- +
+
text1
+
text2
+
+``` + +To clear the content of any element, you can use `ele.innerHTML = ""`. + + + +### 8. outerHTML + +`Element.outerHTML: string [= value]` + +Returns the html markup of the **element and its contents** as a string. + +Can be set, to **replace the element** itself with nodes parsed from the given string. + +**Example 1-** +```jsx +
+
text1
+
+ +console.log(parent.outerHTML) +//
+//
text1
+//
+``` + +**Example 2-** + +Replacing `parent2` with 2 new nodes - + +```jsx +
+
parent 2
+
parent 3
+
+ +parent2.outerHTML = ` +
child 1
+
child 2
+` + +// result html- +
+
child 1
+
child 2
+
parent 3
+
+``` + + +