kalvn's links
Tag cloud
Picture wall
Daily
RSS Feed
  • RSS Feed
  • Daily Feed
  • Weekly Feed
  • Monthly Feed
Filters

Links per page

  • 20 links
  • 50 links
  • 100 links

Filters

Untagged links
Use $ & $$ Instead of document.querySelector/All in JavaScript without jQuery - DEV Community 👩‍💻👨‍💻 https://dev.to/mrahmadawais/use-instead-of-document-queryselector-all-in-javascript-without-jquery-3ef1?ref=dailydevlinks.com
05/04/2019 11:43:11

Une petite astuce pour utiliser $ et $$ comme alias pour document.querySelector et document.querySelectorAll.

const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);

// Change the background color of a class.
$('.class').style.background="#BADA55";

// Change the inner HTML of an ID.
$('#id').innerHTML="<span>Cool beans!</span>";

// Select all images on the webpage.
$$('img')

// Print the image addresses for all the images on a webpage.
$$('img').forEach(img => console.log(img.src))
javascript astuce
3845 links, including 129 private
Shaarli - The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community - Theme by kalvn