Skip to content

Instantly share code, notes, and snippets.

@avireni
avireni / gist:2369668
Created April 12, 2012 17:58
Document ready
$(document).ready(function() {
});
$(function(){
});
@avireni
avireni / gist:2369696
Created April 12, 2012 18:03
Validate Email Address
$(document).ready(function() {
$('#txtEmail').blur(function() {
if(validateEmail('txtEmail'))
{
alert('Email is valid');
}
else
{
alert('Invalid Email Address');
}
@avireni
avireni / gist:2371151
Created April 12, 2012 21:34
Automatic external link open in New Window
$('a').each(function() {
var a = new RegExp('/' + [removed].host + '/');
if(!a.test(this.href)) {
$(this).click(function(event) {
event.preventDefault();
event.stopPropagation();
window.open(this.href, '_blank');
});
}
});
@avireni
avireni / gist:2371176
Created April 12, 2012 21:38
Browser Detection
Target Safari
if( $.browser.safari ) $("#menu li a").css("padding", "1em 1.2em" );
Target anything above IE6
if ($.browser.msie && $.browser.version > 6 ) $("#menu li a").css("padding", "1em 1.8em" );
Target IE6 and below
if ($.browser.msie && $.browser.version <= 6 ) $("#menu li a").css("padding", "1em 1.8em" );
Target Firefox 2 and above
@avireni
avireni / gist:2371185
Created April 12, 2012 21:40
Parse XML with jQuery
function parseXml(xml) {
//find every Tutorial and print the author
$(xml).find("Tutorial").each(function()
{
$("#output").append($(this).attr("author") + "");
});
}
@avireni
avireni / gist:2371213
Created April 12, 2012 21:45
jQuery Ajax request
$(document).ready(function() {
$('#mytarget').load( '/js/remote-file.php', { id: '1' });
});
Call the load function with the address of the script, with optional parameters.
Will call /js/remote-file.php?id=1 and return the results inside the div with the id 'mytarget'
@avireni
avireni / gist:2380010
Created April 13, 2012 20:38
Working with Select Element
//Get the value of a selected option
$('selectElement').val();
//Get the text of a selected option
$('#selectElementId :selected').text();
//Remove an option (e.g. id=1)
$("#selectElementId option[value='1']").remove();
@avireni
avireni / gist:2380710
Created April 13, 2012 23:08
find an option element that’s been selected
$('#radio').find('option:selected');
@avireni
avireni / gist:2380714
Created April 13, 2012 23:09
IE Specific Function
if ($.browser.msie) { }
@avireni
avireni / gist:2380718
Created April 13, 2012 23:10
filter index of an element in an unordered set
$("ul > li").click(function () {
var index = $(this).prevAll().length;
});