Web Development Blog

Twitter

01 Sep, 2010

10 Useful jQuery Snippets

Posted 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) < 7) ) {
	$('body').prepend('<div class="warning">You are using an old version of Internet Explorer which is not supported.  Please upgrade your browser in order to view this website.</div>');
}

2. Add hasJS class to body tag when Javascript is enabled

$('body').addClass('hasJS');

3. Clear default text in input fields on click

Sample Usage:

<input type="text" name="search" class="search" value="Keywords" title="Keywords" />
$('input[type=text]').focus(function() {
    var title = $(this).attr('title');
    if ($(this).val() == title) {
        $(this).val('');
    }
}).blur(function() {
    var title = $(this).attr('title');
    if ($(this).val() == '') {
        $(this).val(title);
    }
});

4. Show/hide more content on click

Sample Usage:

<p><a href="#how-to" class="toggle">How to write a good article?</a></p>
<div id="how-top">
	How to tips go here.
</div>
$('a.toggle').toggle(function() {
	var id = $(this).attr("href");
	$(this).addClass("active");
	$(id).slideDown();
}, function() {
	var id = $(this).attr("href");
	$(this).removeClass("active");
	$(id).slideUp();
});

5. Open Print dialog

Sample Usage:

<a href="#" class="print">Print this page</a>
$('a.print').click(function(){
	window.print();
	return false;
});

6. Add “hover” class to table data (and change the background color of the class via CSS)

$('table').delegate('td', 'hover', function(){
	$(this).toggleClass('hover');
});

7. Open link in a new window if rel is set to external

Sample Usage:

<a href="http://www.google.com" rel="external">Google</a>
$('a[rel=external]').attr('target', '_blank');

8. Add “odd” class to alternate table row (and change the background color of the class via CSS to have stripes effect for table)

$('tr:odd').addClass('odd');  

9. Check if div exists on page

if ( $('#myDiv').length ) {
    // do something with myDiv
}

10. Check/Uncheck all checkboxes

Sample Usage:

<div class="options">
	<ul>
		<li><a href="#" class="select-all">Select All</a></li>
		<li><a href="#" class="reset-all">Reset All</a></li>
	</ul>

	<input type="checkbox" id="option1" /><label for="option1">Option 1</label>
	<input type="checkbox" id="option2" /><label for="option2">Option 2</label>
	<input type="checkbox" id="option3" /><label for="option3">Option 3</label>
	<input type="checkbox" id="option4" /><label for="option4">Option 4</label>
</div>
$('.select-all').live('click', function(){
	$(this).closest('.options').find('input[type=checkbox]').attr('checked', true);
	return false;
});

$('.reset-all').live('click', function(){
	$(this).closest('.options').find('input[type=checkbox]').attr('checked', false);
	return false;
});

August 19, 2010 – Sydney, Australia – Anansi Web Development announces its latest iPhone web app project, Store Locator for iPhone, a powerful yet simple and easy-to-use Store Locator web app for iPhone users. Store Locator for iPhone offers a hosted solution for franchise owners and service providers who are looking to have a mobile presence.

“We built Store Locator for iPhone with Generation Y and mobile technology in mind,” says Ei Sabai Nyo, lead developer for Anansi Web Development. “Generation Y wants information right now, right where they are, and with the Store Locator for iPhone, they will be able to locate stores closest to them with their smart-phones like an iPhone when they are on the road. For businesses, this offers a perfect opportunity to increase their mobile presence and attract more Gen-Y customers.”

Store Locator for iPhone offers:
- Search Stores by Postcode
- Search Nearby Stores (using iPhone built-in GPS)
- Integration with Google Maps app on iPhone (directions, street view, traffic information)
- Native iPhone app look and feel
- Both Portrait & Landscape Support
- An easy to remember app URL, eg: http://sitelocator.mobi/apple/

In addition, Store Locator for iPhone comes with a Back-end Administrator Console which is all web based, allowing business owners to Add, Edit, or Delete store locations from anywhere!

Pricing & Availability
Store Locator for iPhone is available from as little as $50 a month for franchise owners and service providers in Australia.
http://sitelocator.mobi

About Anansi Web Development
Anansi Web Development is a leading Web Development Agency based in Sydney, Australia. It is founded by Ei Sabai Nyo, an aspiring Gen-Y Internet Entrepreneur and Web Developer. The company uses open source technologies and latest web development technologies to provide cutting-edge web and mobile solutions for various organisations. Anansi Web Development is well known for its free web apps developed for the latest and most advanced smart-phone, iPhone. For more information, visit www.anansi.com.au

Contact Info
For press inquiries, and any other questions, please contact hello@anansi.com.au.

We have recently launched our latest iPhone app project, Store Locator for iPhone (http://sitelocator.mobi). It’s a hosted web app solution designed for franchise owners and business in multiple locations in Australia like Woolworths, Kmart, Coles, JB Hi-Fi, Pizza Hut, KFC, WestPac, ANZ, Vodafone, Optus, Medibank, Westfield etc. Have a look at our proof-of-concept Store Locators on iPhone: Apple Store Locator (Australia wide) or Myer Store Locator (NSW only).

Myer Store Locator
Myer Store Locator

Store Locator for iPhone
Get your business found by many smartphone users all over Australia.
Let your customers locate your stores quickly and easily.
Obtain an easy-to-remember web address sitelocator.mobi/yourstore
No need to install anything! Just touch and go!

SIGN UP NOW!

What does it do?

The iPhone Store Locator is a store locator web app that works by postcode or your location via GPS. There are two main components to the Store Locator app; front end and back end.

The front end allows users to locate a store or a business by postcode or by their current location (using iPhone’s built-in GPS). The app will find up to 5 store locations nearby that are within approximately 25 kilometers (15 miles) radius of the specified location.

The back end allows franchise owners and service providers to add the locations of their offices and stores from a web based system and this will automatically geocode addresses. The web based back end enables businesses to add, edit and delete store locations from anywhere via a simple user interface. Businesses can also customise the brand of their front end app by uploading a logo.

Why a web app instead of a native app?

One of the most common questions asked is why we chose a web app over a native app for this project. There were quite a few reasons why we went this way, but let us highlight 3 main benefits for businesses and developers.

1. Benefits For Businesses/Clients

Accessibility (No Download/Install)

There are some popular Store Locator native iPhone apps on App Store like Starbucks Store Locator and McDonalds Store Locator. However, the problem with a native app is that you need to download and install the app first before you can use it. And most people who just need to use the app every once in a while are not likely to download the app. This is why web apps are better. If, for example, you are looking for the nearest Myer store while you are on the road, the first thing you would do is go to Myer website. And on Myer website, you will see a banner ad with a special message for iPhone users that goes something like “Looking for a Myer Store near you? Click here!” and once you click/touch on that link, you will be taken to the Myer Store Locator for iPhone. Since it is a web app, you don’t need to install anything at all. All you need is Internet connection and WebKit-based browser which you already have with your phone.

Portability

With native iPhone apps, the app is only available for one single device – the iPhone. However, with the web app, we have developed it in such a way as it is compatible with most browsers so you can use it not just on an iPhone but also on other smart phones like Android, HTC and Blackberry. It is a great win for businesses because they are able to reach broader smart phone users on multiple devices and platforms with one single app.

Cost Saving

Getting a web app developed is much cheaper compared to getting a native app developed. With Store Locator for iPhone, business owners get the best of both worlds. Unlike having a website where the business owner has to manage hosting, domain name registration, etc, Anansi Store Locator is a hosted solution and therefore all the technical details are looked after by Anansi. There is no need to spend thousands of dollars on development or server infrastructure. Since the app is already developed and hosted by Anansi, all you need is to pay for is a subscription fee. Users of the app won’t need to pay anything as it will be available for free on the web.

2. Benefits For Developers

Ease of Maintenance

Since iPhone web apps don’t need to be approved by Apple to be listed on App Store, the developers (Anansi Web Development), can release updates whenever necessary. Updates take effect immediately the moment they are deployed onto the web server, as oppose to native apps where updates have to be installed by the user on their iPhone. As a web app developer, you can be sure that every user of the app is using one single version, whereas with native iPhone apps, it is possible for users to be using different (outdated) versions.

No Sharing of Revenue Stream

Apple takes about 30% of the price from iPhone apps sold on App Store. However, with web apps, the developer doesn’t need to share the revenue. The cost of running/hosting the web app works out to be much cheaper than sharing the revenue with Apple.

Full Control

Native iPhone apps are like desktop apps that are installed onto your mobile device while web apps are accessed from a web location via a URL. Having a web app means the developer has full control over the app, when it comes to configuring, deploying and upgrading the app. It suits our business model because we need to allow business owners to be able to sign up and make their Store Locator app available as quickly as possible, and this is not possible with native iPhone apps where you have to go through approval from Apple to be listed in the App Store which could take at 1-2 weeks.

iPhone web apps, however, are not without its flaws. Web apps are generally not as sexy as a native app. However, in our case, we are developing a utility app, not a game app, and therefore sexiness is not a requirement! The user interface for the iPhone Store Locator is designed to look and feel like a native app so we feel we are geting the best of both worlds. If you are interested in taking a look or signing up for your business, check out the app site or contact us at any time.

Problogger is having a 7 Link Challenge and inviting all bloggers to participate. The idea of the challenge is to create a blog post that links to 7 different posts on your blog or other people blogs. It sounded fun and so I thought I’d give it a go for this Web Development Blog.

1. First Post
The first ever blog post for Web Development Blog was written almost 5 years ago, on Christmas Day 2005. It is titled Welcome to All Things Web.

2. A post I enjoyed writing the most
I enjoyed writing almost all the Web Development Tutorials on this blog, because writing them gives me a sense of satisfaction from sharing my knowledge with other developers all over the world.

3. A post which had a great discussion
I wrote a tutorial on Removing file extension via .htaccess 3 years ago in 2007 but it is still the most popular blog post on this blog, linked by many and have the most number of comments – mainly by developers and webmasters asking questions or helping each other.

4. A post on someone else’s blog that you wish you’d written
This is a very tough one because there are many blog posts that I like. But if I had to choose one, it would be Why all programmers should blog written by Joerg Mueller. I personally would like to see more blogs by programmers and developers. I think we have way too many designers blogs but not as many developers blogs.

5. Your most helpful post
My most helpful post has to be Web Hosting Comparison Chart that I put together. Before publishing that post, I received many emails from friends and blog readers who asked me the same question, Which host do I recommend? It is very hard to recommend a single hosting company to everyone because the requirements for every website are different. But after writing that blog post, whenever someone asked me the question, I could just give them the link and they can make their own decision. In my opinion, helpful posts are the ones that provide an answer to a question.

6. A post with a title that you are proud of
I am not much of a copywriter, so my post titles are never entertaining or catchy. But this title certainly catches almost everyone’s attention, “Making a Passive Income Online“. And I am proud and amazed at the same time because I didn’t even try hard to come up with that title.

7. A post that you wish more people had read
I wish more people read my rant “So you don’t like ads on websites/blogs” and gave their 2cents worth.

WordPress 3.0 was released a few days ago, and it’s more powerful than it has ever been. And if you are thinking of using WordPress 3 for your blog or even as a CMS, I recommend a self-hosted version rather than the free version hosted on WordPress.com.

So, what are the server requirements to host WordPress 3.0? According to the WordPress official website, your WordPress host should meet the following minimum requirements:

  • PHP 4.3 or greater
  • MySQL 4.1.2 or greater
  • The mod_rewrite Apache module (This is necessary to have pretty SEO-friendly URLs)

Note that WordPress will soon quit support for PHP 4 and MySQL 4 (read official announcement here), so if you are planning to continue using WordPress next year (2011), I strongly recommend that you switch to a hosting that has PHP 5 and MySQL 5 to avoid having to use an older version of WordPress in the near future when the newer versions no longer support PHP 4/MySQL4. Both Dreamhost and Bluehost have PHP 5 and MySQL 5.

I have used more than 10 web hosting providers for my online projects but here are my recommended hosting for WordPress 3.0.

Dreamhost

Dreamhost is an ideal hosting provider for advanced users. Their Control Panel is a bit different to CPanel/Plesk but they have so many more features than CPanel/Plesk if you know what you are doing. And if you install WordPress using “WordPress one-click installer” on dreamhost, they will upgrade it for you automatically. This is a good feature because you don’t have to manually upgrade WordPress whenever a new version comes out. But you need to be careful not to hack the core code or core files of WordPress because your changes will be overwritten when they install a new version. I have heard a lot of mixed reviews about support at dreamhost but I have never really had to contact them because their knowledge base and wiki are quite comprehensive. I am using Dreamhost for this Web Development Blog and it is my recommend hosting provider for developers and technical savvy people. Dreamhost costs $8.53 per month which is a bit more expensive than most shared hosting but you do get what you pay for and you can get $30 off by using this coupon: WEBDEV30.

Test drive Dreamhost now.


Screenshot of Dreamhost's one-click installs

BlueHost

Bluehost is an ideal hosting provider for basic users. Each hosting account comes with a CPanel and one click install feature to install WordPress on your hosting account in less than 3 minutes. The install feature also allows you to install a previous version of WordPress so if, for some reason, you need to install WordPress 2.9 instead of WordPress 3.0 for plugin compatibility reasons, you can do so easily. The following video shows you how to install WordPress on Bluehost using their one click install. I am using Bluehost for a few of my websites. At $6.95/month with a free domain name for life and unlimited domain hosting, the price is very affordable.

Test drive BlueHost now.


Video Tutorial of how to install WordPress using SimpleScripts on BlueHost

ebook
Subscribe to our newsletter and receive FREE e-book "7 Days Exercise to Build More Traffic To Your Blog"
Your name:  
Your email:  

  • About
    The blog Web Development Blog is where I keep myself up to date with the latest technologies in the industry and share my ideas and thoug...
  • Adsense Tips and Tricks
    With personal and commercial blogs, community websites, and social pages becoming the hot topic of the Internet in the last few years, many...
  • Advertise With Us
    Web Development Blog is a blog about Web Development, Web Design, Web Applications, Web 2.0, AJAX, Search Engine Optimisation, Latest Techno...
  • Archive
    Grab yourself a cup of coffee or tea, sit back and browse through an archive of all the blog posts on Web Development Blog....
  • Choosing a Content Management System
    The most commonly asked question when it comes to Content Management System is whether to build or buy (pre-built). While there are many fa...
  • Coupons
    Use the following coupon codes, promos and discount codes to save money on web hosting, domain names, website templates, ebooks, software, p...
  • Customised WordPress Themes
    If you would like a customised WordPress theme for your blog or your website, read on: (or head to WordPress Themes page to get free WordPre...
  • Favourite Poems
    If by Rudyard Kipling If you can keep your head when all about you Are losing theirs and blaming it on you, If you can trust yourself w...
  • Favourites
    Books Web Development Books Magazines Glamour Reader's Digest Software Adobe Photoshop CS4 Trend Micro Antivirus + Antispyw...
  • How to Start a Blog?
    What's a blog? According to Wikipedia, a blog is a user-generated website where entries are made in journal style and displayed in a reve...
  • Introduction to JSP Standard Tag Library (JSTL Basics)
    Tag libraries to include in your .jsp page <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> &l...
  • Links
    Free Anonymous Proxy Increases your privacy and security on the Internet by using our free, fast and easy to use web proxy. data backu...
  • Making a Passive Income Online
    Passive income, in my opinion, means an income which does not require a lot of regular maintenance work or continuing effort. I have been t...
  • Online Distribution Channels
    One of the importances of any website or business is to bring your products or services to the right people and to reach the target audience...
  • Recent Projects
    Followings are some of the recent projects I have done in 2006 -- 2007. Check out my latest business venture Web design Sydney to get your...
  • Recommended Web Development Books
    Many developers often ask me what books I read and what books I recommend in regards to web development and web technologies such as AJAX, J...
  • Search
    Looking for something on Web Developement Blog? Use this search tool powered by Google Custom Search to find what you are looking for just ...
  • Seven Tips to Building an Online Presence for your Business
    1. Get a domain name for your business The first and foremost step in building an online presence is to secure a domain name for your busi...
  • Seven Tips to Increasing Your Website’s Traffic Using SEO
    SEO is the buzz word - many people have mentioned it and many have heard of it too, but very few people know how to implement it properly. ...
  • Subscribe
    Newsletter [newsletter] RSS 2.0 feeds Entries feed Comments feed Subscribe using your favourite web-based or desktop feed r...
  • Useful Linux Commands
    Find files older than 60 days find * -mtime +60 Delete files in backup folder which are older than 60 days rm -f `find /backup/ -mtime ...
  • Web Design Tips
    Nowadays, having a website for your business is like having a phone number. Almost every business has their own website, with their own doma...
  • Web Development Books
    Many developers often ask me what books I read and what books I recommend in regards to web development and web technologies such as AJAX, J...
  • Web Hosting Comparison Chart
    The following are some of the most popular web hosting providers. I have personally used the recommended ones. Hosting coupon codes will ...
  • Web Standards
    Web Standards is defined as a set of rules or specifications that should be followed when developing a website.  The main objectives o...
  • WordPress Themes
    All WordPress themes are designed and coded by esn studio, and licensed under GPL license. If you would like a customised WordPress theme fo...
  • Sam: Useful. I always forget the rel target one
  • Chronic Tinnitus: Hi, Thanks for taking the time to discuss a really confusing matter - I find Plesk so much more awkward than the cpanel that I'm used to. Thanks Chr
  • Serhiy: I personally liked the web hosting comparison chart. Especially the recommended *. I got Bluehost :) .-= Serhiy´s last blog ..

Interests

Web development, Web design, Open source technologies, Portal development, APIs, Web services, Social media applications, Search engine optimisation, Mobile application development, iPhone Apps, Web 2.0, Web 3.0, Latest Internet technologies

Misc.

  • bluehost Hosting $6.95/month
  • Joomla Templates