Prints the selected element html and text
Important link:
.empty()
.html()
To select tag with attributes
<input value="123" name="data[text_amount]">
$('input[name="data[text_amount]"]'));
Sample console of a selected object
'0': <ref *1> {
type: 'tag',
},
children: [],
prev: [Circular *1],
parent: [Object]
next: [Circular *1],
prev: [Object],
name: 'head',
attribs: {},
}
},
name: 'description',
content: 'Help with 4DOS language is provided at the assignmenthelp.net. We do all type of help for 4DOS programming language.'
type: 'text',
next: [Object],
data: '\n',
type: 'text',
parent: {
type: 'tag',
prev: [Object],
parent: [Object]
normalizeWhitespace: false,
xmlMode: false,
type: 'root',
name: 'root',
parent: null
},
decodeEntities: true
},
prevObject: initialize {
'0': {
next: [Object],
prev: [Object],
normalizeWhitespace: false,
xmlMode: false,
options: [Object],
length: 1,
'0': [Object],
options: [Object],
}
Print element in the object
console.log(listItems.length); // 2
Print of idx
0
1
Print of el with attributes
{
name: 'keywords',
content: 'Help with 4DOS language is provided at the assignmenthelp.net. We do all type of help for 4DOS programming language.'
}
Print of each element
console.log(meta[1].attribs);
Output
}
{
Prints the selected element html and text
.html()
const html = `<div>
<Head>
</Head>
</div>`;
<title>4DOS Assignment Help | 4DOS Homework Help | 4DOS Project Help</title>
<meta name="keywords" content="4DOS Assignment Help, Programming Assignment Help, Learn 4DOS Online, 4DOS Programming help, 4DOS programming language, Programming help with 4DOS">
.text()
Some random code
country.name = $(el).children("a").text();
country.iso3 = $(el).children("span").text();
One example to get meta information with working code.
<meta name="keywords" content="4DOS Assignment Help, Programming Assignment Help, Learn 4DOS Online, 4DOS Programming help, 4DOS programming language, Programming help with 4DOS" />
<meta name="description" content="Help with 4DOS language is provided at the assignmenthelp.net. We do all type of help for 4DOS programming language." />
const metaData = {} ;
const title = $('title').text();
if (meta) {
meta.each((index, element) => {
}
});
title: '4DOS Assignment Help | 4DOS Homework Help | 4DOS Project Help',
keywords: '4DOS Assignment Help, Programming Assignment Help, Learn 4DOS Online, 4DOS Programming help, 4DOS programming language, Programming help with 4DOS',
Delete a node from html
<Head>
<title>4DOS Assignment Help | 4DOS Homework Help | 4DOS Project Help</title>
</div>`;
const $ = cheerio.load(html);
Append and prepend the element
const ul = $("ul");
ul.append("<li>Banana</li>");
async function getData() {
try {
const htmlWithoutHead = $('head').remove().end().html()
console.log(htmlWithoutHead);
}
getData() ;