01 Sep, 2010
Posted by: eisabai In: Snippets
Following are 10 Useful jQuery snippets for any website. To use these snippets, you must include jQuery library in your page first and then add the snippets inside DOM ready function as follow:
$(document).ready(function() {
// add your snippets here
});
1. Display Warning Message for IE 6 Users
if ( (jQuery.browser.msie) && (parseInt(jQuery.browser.version) < [...]
17 Jun, 2010
Posted by: eisabai In: Snippets
The following Javascript will clear default text value in input boxes when you click on them. To trigger the Javascript, you’ll need to specify both title and value attributes and set class of the input field to “text”. jQuery library is required for this to work.
Javascript
$(‘.text’).focus(function () {
if ($(this).val() == $(this).attr(“title”)) [...]
I needed a script that copies a text (in my case, coupon code) onto clipboard and then open the web address associated with the coupon in a new window for my Coupons for Webmasters page. For the clipboard copying, I’m using ZeroClipboard script written by Joseph Huckaby. ZeroClipboard is a free and [...]
This is one of the most commonly used piece of code for jQuery. Often times, we need to check if a div/element exists in the page before processing a block of script (eg: replacing the content of the div).
if ( $(“#message”).length ) {
$(‘#message’).text(“Hello!”);
}
Here’s a snippet of CSS and HTML code that aligns an image in center (horizontally) and middle (vertically). Tested in Firefox, IE, Chrome and Safari.
CSS
#enter {
position: absolute;
text-align: center;
left: 50%;
top: 50%;
margin: -120px auto 0 -130px; /* value of top margin: height of the image divide by 2 (ie: 240 / 2), value of [...]