Languages
[Edit]
EN

JavaScript - document querySelector and querySelectorAll most common usage in chrome console

2 points
Created by:
telsa
352

Example:

console.log([...document.querySelectorAll('#video-title')]
    .map(entry => `${entry.text}\n${entry.href}`).join('\n\n'));

[...document.querySelectorAll('#video-title')].map(entry => entry.text);
[...document.querySelectorAll('#video-title')].map(entry => entry.href);
[...document.querySelectorAll('#video-title')].map(entry => ({name: entry.text, link: entry.href}));
[...document.querySelectorAll('#video-title')].map(entry => entry.href).join(' ');
[...document.querySelectorAll('#video-title')].map(entry => `${entry.text} ${entry.href}`).join('\n');
console.log([...document.querySelectorAll('#video-title')].map(entry => `${entry.text} ${entry.href}`).join('\n'));

source: Youtube - print all video title and links in console using JavaScript - Dirask

 

Example:

[...document.querySelectorAll('.my-class a')].map(entry => entry.href);

// result:
// 0: "https://example1.com/"
// 1: "https://example2.com/"
// 2: "https://example3.com/"

 

Example:

document.querySelectorAll('.my-class a')[0].href
'https://example1.com/'
document.querySelectorAll('.my-class a')[1].href
'https://example2.com/'
document.querySelectorAll('.my-class a')[2].href
'https://example3.com/'

 

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join