Util
create()
create(tag: string): QueryResult;
Create an element, return QueryResult
. Its usage is similar to document.createElement()
.
Example
const container = nashi.create('div').class('container');
nashi('body').firstChild(container);
//The tag name provided ('123') is not a valid name.
const error = nashi.create('123');
fromHTML()
fromHTML(html: string): QueryResult;
Create a QueryResult
from HTML string. Its usage is similar to element.innerHTML
.
Example
const container = nashi.fromHTML('<h1>nashi is perfect!</h1>');
nashi('body').firstChild(container);
merge()
merge(...args: Array<QueryResult>): QueryResult;
Merge any amount of QueryResult
, return new QueryResult
. so you can operate them at the same time!
Example
const QRarr = nashi.merge(nashi('p'), nashi('button'));
console.log(QRarr.node); //(2) [p, button]
QRarr.class('QRarr').text('nashi is perfect!').css('color', 'red');
equal()
equal(first: QueryResult, second: QueryResult): boolean;
Return whether two QueryResult
are equal.
Example
const para1 = nashi.create('p');
const para2 = nashi.create('p');
console.log(nashi.equal(para1, para2)); //false
console.log(nashi.equal(nashi('p'), nashi('p'))); //true
clone()
clone(queryResult: QueryResult): QueryResult;
Deep clone and return QueryResult
.
Example
const para1 = nashi('p');
const para2 = nashi.clone(para1);
console.log(para2.node); //[[p]
console.log(nashi.equal(para1, para2)); //true
para2.text('nashi is perfect!');
console.log(para1.text()); //nashi is perfect!