Use images like checkboxes

Pure semantic HTML/CSS solution This is easy to implement on your own, no pre-made solution necessary. Also it will teach you a lot as you don’t seem too easy with CSS. This is what you need to do: Your checkboxes need to have distinct id attributes. This allows you to connect a <label> to it, using the label’s for-attribute. Example: … Read more

How do I disable right click on my web page?

You can do that with JavaScript by adding an event listener for the “contextmenu” event and calling the preventDefault() method: That being said: DON’T DO IT. Why? Because it achieves nothing other than annoying users. Also many browsers have a security option to disallow disabling of the right click (context) menu anyway. Not sure why you’d want to. … Read more

Merge/flatten an array of arrays

You can use concat to merge arrays:  Run code snippetExpand snippet Using the apply method of concat will just take the second parameter as an array, so the last line is identical to this: There is also the Array.prototype.flat() method (introduced in ES2019) which you could use to flatten the arrays, although it is only available in Node.js starting with version 11, and not … Read more

What’s the difference between console.dir and console.log?

In Firefox, these function behave quite differently: log only prints out a toString representation, whereas dir prints out a navigable tree. In Chrome, log already prints out a tree — most of the time. However, Chrome’s log still stringifies certain classes of objects, even if they have properties. Perhaps the clearest example of a difference is a regular expression: You can also see a clear difference … Read more

What is the difference between call and apply?

The difference is that apply lets you invoke the function with arguments as an array; call requires the parameters be listed explicitly. A useful mnemonic is “A for array and C for comma.” See MDN’s documentation on apply and call. Pseudo syntax: theFunction.apply(valueForThis, arrayOfArgs) theFunction.call(valueForThis, arg1, arg2, …) There is also, as of ES6, the possibility to spread the array for use with the call function, you can see the compatibilities here. Sample code:

jQuery animate backgroundColor

The color plugin is only 4kb so much cheaper than the UI library. Of course you’ll want to use a decent version of the plugin and not some buggy old thing which doesn’t handle Safari and crashes when the transitions are too fast. Since a minified version isn’t supplied you might like test various compressors and make your own min version. … Read more