This file contains 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
// simple request with a fallback | |
function getXHR() { | |
if (window.XMLHttpRequest) { | |
return new XMLHttpRequest(); | |
} | |
try { | |
return new ActiveXObject('MSXML2.XMLHTTP.6.0'); | |
} |
This file contains 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 frag = document.createDocumentFragment(); | |
ajaxResult.items.forEach(function(item) { | |
// Create the LI element | |
var li = document.createElement('li'); | |
li.innerHTML = item.text; | |
// Do some normal node operations on the LI here, | |
// like add classes, modify attributes, | |
// add event listeners, add child nodes, etc. |
This file contains 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
// figure out which click is left or right | |
$(element).live('click', function(e) { | |
if( (!$.browser.msie && e.button == 0) || ($.browser.msie && e.button == 1) ) { | |
alert("Left Button"); | |
} | |
else if(e.button == 2) | |
alert("Right Button"); | |
}); |
This file contains 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
// Validate date of birth | |
$("#frm1").submit(function(){ | |
var d = $("#day").val(); | |
var mth = $("#month").val(); | |
var yr = $("#year").val(); | |
// arbitrary number for example | |
var age = 18; | |
This file contains 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
// see what key was pressed | |
$(function() { | |
$(document).keypress(function(e){ | |
switch(e.which){ | |
// "ENTER" | |
case 13: | |
alert('enter pressed'); | |
break; | |
This file contains 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() { | |
var f = []; | |
$.ajax({ | |
url: "imgz.js", | |
type: "GET", | |
contentType: "json", | |
cache: true, | |
success: function(data) { | |
var j = JSON.parse(data); | |
var $c = $("#container"); |
This file contains 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
/* | |
* Options: | |
* - before (string): HTML code before the tweet. | |
* - after (string): HTML code after the tweet. | |
* - tweets (numeric): number of tweets to display. | |
* | |
* Example: | |
* | |
* <script type="text/javascript" charset="utf-8"> | |
* $(document).ready(function() { |
This file contains 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
//store the URL | |
var url = "http://vimeo.com/71673549"; | |
//extract the ID | |
var rgx = /\/\/(www\.)?vimeo.com\/(\d+)($|\/)/; | |
//the ID: 71673549 | |
var id = url.match(rgx); | |
var width = '640'; |
This file contains 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
// How to get client ip address with jQuery | |
$.getJSON("http://jsonip.appspot.com?callback=?",function(data){ | |
alert( "Your ip: " + data.ip); | |
}); | |
// How to parse XML with jQuery | |
// file.xml: |
NewerOlder