The most common JavaScript and jQuery code snippets

I have collected the most common JavaScript and jQuery snippets that we use almost for every project. Honestly I couldn’t write a jQuery “document-ready” function on a blank piece of paper because my memory is not too sharp. This resource will help keeping these all together so we can always sneak a peek if necessary.

Check out the interactive JavaScript Cheat Sheet to find them all in one place!

Show an element when another is clicked:

$(document).ready(function () {
    $("#button").click(function(event) {

Go through every instance of a class:

$(".myclass").each(function() {

Get the content of an element by ID

var x = document.getElementById("demo").innerHTML;