This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var nodes = document.getElementsByTagName('*'); | |
| for (var i = nodes.length - 1; i >= 0; i--) { | |
| nodes[i].addEventListener('click', function() { | |
| console.log('You clicked element #' + i); | |
| }); | |
| } | |
| var nodes = document.getElementsByTagName('*'); | |
| for (var i = nodes.length - 1; i >= 0; i--) { | |
| nodes[i].addEventListener('click', (function(i) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (function($){ | |
| $.fn.yourPluginName = function(){ | |
| // Your code goes here | |
| return this; | |
| }; | |
| })(jQuery); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var x = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'], | |
| y = []; | |
| for (var i = 0; i < x.length; i++) { | |
| y[y.length] = x[i]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var x = 0; | |
| // this will toggle between 0 and 1 everytime is reset | |
| x ^= 1; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [].forEach.call($$("*"),function(a){ | |
| a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16) | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var re = /(\w+)\s(\w+)/; | |
| var str = "John Smith"; | |
| var newstr = str.replace(re, "$2, $1"); | |
| console.log(newstr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| prices = jQuery('#item-page-wrapper .price-section .a-color-price').text() | |
| prices = prices.replace(/\s/g,'').split('£'); | |
| total = 0; | |
| var v; | |
| for(var i = 0; i < prices.length; i++) { | |
| v = parseFloat(prices[i]); | |
| if (!isNaN(v)) total += v; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $.getJSON('/my/url', function(data) { | |
| }); | |
| vs | |
| request = new XMLHttpRequest(); | |
| request.open('GET', '/my/url', true); | |
| request.onload = function() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function makeId() | |
| { | |
| var txt = "", | |
| rand = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
| for (var i = 5; i >= 0; i--) { | |
| txt += rand.charAt(Math.floor(Math.random() * rand.length)); | |
| } | |
| return txt; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var twice_37 = 0; | |
| $(document).on('keydown', function( e ){ | |
| var key = e.which; | |
| if(key==37){ | |
| twice_37 += 1; // almost :) | |
| if(twice_37==2){ | |
| alert('Do something! you pressed twice left!'); |