JavaScript – Simple Copy and Clone

There’s a bunch of ways to do this. I think what follows is the most simple, logical, portable and transparent. Copy:


Packaged up:

Simple HTML (string) to DocumentFragment (usable Node)

JavaScript – recursively construct (provide) a namespace

Use like:


JavaScript – get index of child element


Change content of before or after psuedo element with JavaScript

Set the content to an attribute, and change the attribute with script.


Simple JavaScript to Query Parameter Serializer


Seriously Simple JavaScript Cookie Management

Here’s the basic idea of one way to manage cookies with JavaScript. As always, there are more robust libraries available, but here’s the upshot:


Why does indexOf return -1

Both Array.prototype.indexOf and String.prototype.indexOf (as well as all their counterparts in other languages) return -1 when a match is not found. This can seem less-than-obvious to new learners. I often use this example to illustrate why:

Simple requestAnimationFrame polyfill

While there are definitely better versions, as always I’m concerned with the fundamental function – and for requestAnimationFrame it’s pretty straightforward:

Basic JavaScript Tasks (vanilla, framework agnostic)

Create a reference

Create a function

Create an array

Create an object

Assign properties to an object

Iterate through an array

Iterate over an object

Get a reference to an element

Get a reference to a collection of elements

Modify an element’s style

Create an […]