Attribute
text()
// Getter
text(): string;
// Setter
text(string: string): QueryResult;
Get or set element's innerText
.
example
// Getter
console.log(nashi("p").text()) // nashi is small
//Setter
nashi("p").text("nashi")
console.log(nashi("p").text()) // nashi
<!-- Before -->
<p>nashi is small</p>
<!-- After -->
<p>nashi</p>
class()
// Getter
class(): string;
// Setter
class(className: string): QueryResult;
Get or set element's className
.
example
// Getter
console.log(nashi("p").class()) // content
console.log(document.querySelector("p").className); // content
// Setter
nashi("p").class("small")
<!-- Before -->
<p class="content">nashi is small</p>
<!-- After -->
<p class="small">nashi is small</p>
id()
// Getter
id(): string;
// Setter
id(id: string): QueryResult;
Get or set element's id
.
example
// Getter
console.log(nashi("p").id()) // content
console.log(document.querySelector("p").id); // content
// Setter
nashi("p").id("small")
<!-- Before -->
<p id="content">nashi is small</p>
<!-- After -->
<p id="small">nashi is small</p>
addClass()
// Setter
addClass(className: string): QueryResult;
Add a className .
example
// Getter
nashi("p").addClass("nashi")
<!-- Before -->
<p>nashi is small</p>
<!-- After -->
<p class="nashi">nashi is small</p>
removeClass()
// Setter
removeClass(className: string): QueryResult;
Remove a className .
example
// Getter
nashi("p").removeClass("small")
<!-- Before -->
<p class="nashi small">nashi is small</p>
<!-- After -->
<p class="nashi">nashi is small</p>
hasClass()
// Getter
hasClass(className: string): boolean;
Return if element has the className .
example
<p class="small">nashi is small</p>
console.log(nashi("p").hasClass("small")); // true
console.log(nashi("p").hasClass("nashi")) // false
toggleClass()
// Setter
toggleClass(className: string): QueryResult;
If element have the className , remove it . Otherwise, add it .
example
<p class="nashi small">nashi is small</p>
const para = nashi("p")
para.toggleClass("small")
console.log(para.class()); // nashi
para.toggleClass("small")
console.log(para.class()); // nashi small
attr()
// Getter
attr(key: string): string;
// Setter
attr(key: string, value: string): QueryResult;
Get or set element's attribute
.
example
const para = nashi("p")
console.log(para.attr("class")); // nashi
para.attr("class", "nashi small")
console.log(para.class()); // nashi small
<!--Before-->
<p class="nashi">nashi is small</p>
<!--After-->
<p class="nashi small">nashi is small</p>
prop()
// Getter
prop(key: string): string;
// Setter
prop(key: string, value: string): QueryResult;
Get or set element's property
.
html()
html(): string;
html(html: string): QueryResult;
Get or set element's innerHTML
.
example
const dv = nashi("div")
dv.html("<p>nashi is small</p>")
console.log(dv.html());
<!--Before-->
<div></div>
<!--After-->
<div>
<p>nashi is small</p>
</div>
accesskey()
// Getter
accesskey(): string;
// Setter
accesskey(key: string): QueryResult;
Get or set element's accesskey
.
removeAttr()
// Setter
removeAttr(key: string): QueryResult
Remove element's attribute .
example
const para = nashi("p")
para.removeAttr("class")
console.log(para.class()); // ""
<!--Before-->
<p class="nashi">small</p>
<!--After-->
<p class="">small</p>