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.

Show an element when another is clicked:

$(document).ready(function () {
    $("#button").click(function(event) {
        $("#box").show();
    });
});

Go through every instance of a class:

$(".myclass").each(function() {
    console.log($(this).html());
});

Get the content of an element by ID

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