learning jQuery


I stumbled upon Rebecca Murphy‘s jqfundamentals and found it to be a gentle introduction to jQuery. Well, I use jQuery a lot – well, let’s just say I copy prefabricated solutions – so I felt it’ll do no harm to learn how to write jQuery itself. So far it’s been lovely, Rebecca’s piece is great and I must confess I’m impressed by JavaScript‘s capabilities.

There are exercises at the end of some of the chapters in the book; I tried out some and got exposed to the raw power of jQuery. One of the tasks involved removing the label for a search input from the DOM and setting that label’s text as the search input’s value. It also involved clearing the search input’s text whenever it was in focus and resetting the text if the user didn’t type in anything.

Here’s my code…

$(document).ready(function () {
var $search = $('#search'); //Get the search form
var $input = $search.find('input.input_text'); // search input
var label = $search.find('label').remove().text(); //remove the label
$input
.val(label)
.addClass('hint')
.bind('focus',function() {
$(this).removeClass('hint').val('');
})
.bind('blur', function(){
if (!$.trim($(this).val())) // Check if the user didn't enter text and reset the text
{
$(this).val(label).addClass('hint');
}
});
});

Well, I know this isn’t much but it’s a start – I’m still a novice.

If you’re interested in learning, do check out her site: jqfundamentals.com. If you’ll like to learn about software engineering; try watching the CS**** videos on Stanford’s YouTube channel -> they’ve got lots of interesting stuff that’ll improve and boost your knowledge.

Next week, I’ll write about what I learnt again insha Allah ( God willing ) :D


4 Comments

·

Leave a Reply

  1. Thanks for that piece of info. I just discovered endless possibilities using javascript and I’m beginning to love it. I would check out the site and share my discoveries too.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s