Skip to content

Instantly share code, notes, and snippets.

@lsitters
Created December 14, 2009 21:18
Show Gist options
  • Save lsitters/256436 to your computer and use it in GitHub Desktop.
Save lsitters/256436 to your computer and use it in GitHub Desktop.
jQuery Snippets
//A. Target Safari
if( $.browser.safari ) {};
//B. Target anything above IE6
if ($.browser.msie && $.browser.version > 6 ) {};
//C. Target IE6 and below
if ($.browser.msie && $.browser.version <= 6 ) {};
//D. Target Firefox 2 and above
if ($.browser.mozilla && $.browser.version >= "1.8" ) {};
function equalHeight(group) {
tallest = 0;
group.each(function() {
thisHeight = $(this).height();
if(thisHeight > tallest) {
tallest = thisHeight;
}
});
group.height(tallest);
}
/*
Usage:
$(document).ready(function() {
equalHeight($(".recent-article"));
equalHeight($(".footer-col"));
});
*/
$('#myImage').attr('src', 'image.jpg').load(function() {
alert('Image Loaded');
});
/*
The target="blank" attribute can be useful when you want a link to be opened in a new tab or window. Though, the target="blank" attribute is not valid XHTML 1.0 Strict.
using jQuery, you can achieve the same functionality without having validation problems.
*/
$("a[@rel~='external']").click( function() {
window.open( $(this).attr('href') );
return false;
});
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
function parseXml(xml)
{
//find every Tutorial and print the author
$(xml).find("Tutorial").each(function()
{
$("#output").append($(this).attr("author") + "<br />");
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment