Easily Manipulate DOM with DOM.js - As Easy as possible!!!
<script src="index.js" type="module" defer></script>
// index.js
import DOM from "https://codeabinash.github.io/DOM.js/DOM.js"
Do not use the
DOMElem
andDOM
as variable name or function or class name etc. because it is in use internally already
DOM(selector)
here selector
works like querySelector
as needed
class
id
tagName
let h1 = DOM("h1")
let spans = DOM("span")
let myDiv = DOM("#myDiv")
let s = DOM("h1 .me")
let div = DOM("#myDiv")
let oldDiv = DOM(div)
let name = document.getElementById("name")
let domName = DOM(name)
console.log(domName.text);
// console : Abinash
<h1>Hello</h1>
<h1>My name is <span>Abinash</span></h1>
let name = DOM("h1 span")
name.text = "Pekachu"
Hello
My name is Pekachu
<h1>Hello</h1>
<h1>My name is <span>Abinash</span></h1>
let h1 = DOM("h1")
let name = h1.select("span") //Select "span" from h1
console.log(name.text);
// console : Abinash
<h1>Hello</h1>
<h1 id="d">Hello</h1>
<h1>Hello</h1>
DOM("#d").text = "Pekachu"
Hello
Pekachu
Hello
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
DOM("h1").text = "All are changed"
All are changed
All are changed
All are changed
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
DOM("h1").text = ["Abinash", "Pekachu", 10];
Abinash
Pekachu
10
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
DOM("h1").text = {
text:["Abinash", "Pekachu", 10],
appendType : "prepend"
};
AbinashHello
PekachuHello
10Hello
DOM("h1").text = {
text:["Abinash", "Pekachu"],
ignore : true,
appendType : "prepend"
};
AbinashHello
PekachuHello
Hello
DOM("h1").text = {
text:["Abinash", "Pekachu"],
ignore : false,
appendType : "prepend"
};
ERROR : Length of input Array and selected DOM elements are not Same
Hello Hello Hello
If length of texts in text:[arr]
are not same as selected DOM elements and used ignore:false
or ignore
not specified then, there will be a error : Length of input Array and selected DOM elements are not Same
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
DOM("h1").text = [
{text : "1", appendType : "append"},
"Hii",
{text : "2", appendType : "prepend"},
{text : "Abinash"}
]
Hello1
Hii
2Hello
Abinash
<h1 id="d">JavaScript</h1>
let elem = DOM("#d")
elem.text = { text : " Abinash", appendType : "append" }
// JavaScript Abinash
<h1 id="d">JavaScript</h1>
let elem = DOM("#d")
elem.text = { text : "Abinash", appendType : "prepend" }
//console : AbinashJavaScript
NOTE : Here in the place of
text : "Text"
,data : "Text"
can also be used.
<h1>Hello</h1>
<h1 id="d">JavaScript</h1>
<h1>Hello</h1>
let d = DOM("#d")
console.log(d.text)
//console : JavaScript
let elements = DOM("h1")
console.log(elements.text);
// console : (3)Β ['Hello', 'JavaScript', 'Hello']
NOTE : If there is more than 1 DOM element is elected it
text
returns texts as array, otherwise it returns a string value
let elements = DOM("h1")
console.log(elements.textArr);
NOTE :
textArr
always returns as array for single DOM elements too.
let name = DOM("#name")
let nativeDOM = name.dom
//Original DOM (Native)
NOTE :
dom
returns single DOM element if there is a single DOM element is selected otherwise it returns array of DOM elements. To return always as array usedomArr
instead ofdom
. it always returnsarray
for single DOM elements too.let name = DOM("#name") let nativeDOM = name.domArr //Original DOM (Native)
<h1>Hello</h1>
<h1>Abinash</h1>
<h1>Hi</h1>
let h1 = DOM("h1")
let name = h1.n(1) // 2nd Element
console.log(name.text); // Abinash
console.log(DOM("h1").n(2).text) // Hi
css
, eventListener
, class
, id
, transitions
etc β¦ Coming Soon π€©π€©π€©