diff --git a/docs/create-modify-element.mdx b/docs/create-modify-element.mdx index 73a60af..78cb9e1 100644 --- a/docs/create-modify-element.mdx +++ b/docs/create-modify-element.mdx @@ -62,7 +62,7 @@ for (var p of paragraphs) { ## Create / insert element -### 1. `createElement` +### 1. `createElement()` The `document.createElement` method creates a new HTML element, taking the tag name (`"div"`) as first argument. @@ -86,4 +86,19 @@ var newEle = document.createElement("div") // creates
-[Read on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement) \ No newline at end of file +[Read on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement) + +### 2. `setAttribute()` + +Every element has a `.setAttribute(name, value)` method, which can add/modify a attribute on the current element. + +`name` - the attribute name which should be added. Ex- `"type"`. +`value` - value of the attribute. Ex- `"text"`. + +```js +var newInput = document.createElement("input") + +newInput.setAttribute("type", "text") // +``` + +[Read on MDN](https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute) \ No newline at end of file