Skip to content

Instantly share code, notes, and snippets.


Mathias Bynens mathiasbynens

View GitHub Profile
View toggleAttr() jQuery plugin
* toggleAttr() jQuery plugin
* @link
* @description Used to toggle selected="selected", disabled="disabled", checked="checked" etc…
* @author Mathias Bynens <>
jQuery.fn.toggleAttr = function(attr) {
return this.each(function() {
var $this = $(this);
$this.attr(attr) ? $this.removeAttr(attr) : $this.attr(attr, attr);
mathiasbynens / .gitignore
Last active Mar 11, 2020
Unicode version diff for ECMAScript
View .gitignore
mathiasbynens / hide-jimmy-wales.user.js
Created Nov 21, 2011
Userscript that hides Jimmy Wales on Wikipedia
View hide-jimmy-wales.user.js
// ==UserScript==
// @name Hide Jimmy Wales.
// @match http://**
// ==/UserScript==
(function() {
var banner = document.getElementById('siteNotice');
banner && = 'none';
mathiasbynens /
Created Apr 22, 2011
Improved swipe gestures plugin for jQuery

Improved swipe gestures plugin for jQuery

What was changed (compared to the original v0.1.2):

  • Don’t modify the default settings internally.
  • Merge the options recursively (deep copy) so that the custom threshold values actually get used.
  • Allow overriding the options globally through $.fn.swipe.options.
  • Use namespaced jQuery events (using the swipe namespace) instead of DOM2 addEventListener to prevent errors in old IEs.
  • Simplified and optimized code.
  • Changed swipeLeft and swipeRight functions to be called within the context of the bound element. Thanks, @kswedberg!
mathiasbynens / jquery.fluid-youtube-videos-original.js
Created Jun 8, 2011
Fluid width YouTube videos of different aspect ratios, by Chris Coyier
View jquery.fluid-youtube-videos-original.js
// Original code from
$(function() {
// find all videos
var allVideos = $("iframe[src^='']"),
// The thing that is fluid width
body = $("body"),
View output.txt
└ IP:
└ IP:
└ IP:
└ IP:
└ IP:
mathiasbynens / jquery.preload.js
Created Apr 22, 2010
JavaScript preload() function
View jquery.preload.js
* $.preload() function for jQuery –
* Preload images, CSS and JavaScript files without executing them
* Script by Stoyan Stefanov –
* Slightly rewritten by Mathias Bynens –
* Note that since this script relies on jQuery, the preloading process will not start until jQuery has finished loading.
jQuery.preload = function(array) {
var length = array.length,
View optimized-async-ga-snippet.html
<!-- See -->
<!-- Gisted for P. Ireland -->
<script>var _gaq=[['_setAccount','UA-XXXXX-X'],['_trackPageview']];(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.src='//';s.parentNode.insertBefore(g,s)}(document,'script'))</script>
mathiasbynens / bf.js
Created Jul 17, 2015
How many hex-formatted Unicode code points can be mistaken for a number in scientific notation? Which ones are those?
View bf.js
'use strict';
const pad = function(string) {
const totalCharacters = 4;
return string.length < totalCharacters ?
(Array(totalCharacters + 1).join('0') + string).slice(-totalCharacters) :
const UNICODE_MIN = 0x0;
mathiasbynens /
Last active Aug 4, 2018
List of things that broke with the Opera 15 release due to the switch to Blink/Chromium (Web features, not UI-specific stuff)