Archive for the ‘jQuery’ Category

Articles

Ident Code in Textarea

In jQuery on December 21, 2011 by patrellery Tagged: ,

How many times you wanted to use the tab in your textarea ?

I’m sure a lot!

Here’s a very simple jQuery code that will allow to use the TAB key in a textarea!


$(document).ready(function(e) {

// Using the
$('textarea.tab').keydown(function(e) {
if(e.keyCode == 9) {
var start = $(this).get(0).selectionStart;
$(this).val($(this).val().substring(0, start) + "\t" + $(this).val().substring($(this).get(0).selectionEnd));
$(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 1;
return false;
}
});

// Using Spaces
$('textarea.space').keydown(function(e) {
if(e.keyCode == 9) {
var start = $(this).get(0).selectionStart;
$(this).val($(this).val().substring(0, start) + " " + $(this).val().substring($(this).get(0).selectionEnd));
$(this).get(0).selectionStart = $(this).get(0).selectionEnd = start + 4;
return false;
}
});
});

View the full article at www.bookofzeus.com/articles/indent-code-in-textarea-using-jquery/

Advertisements

Articles

$this vs $(this) in jQuery

In jQuery on October 11, 2011 by patrellery

How many times we try to use this and we need to use $(this) and vice versa? Well here’s a quick explanation on how to differentiate these two objects
Read More »

Articles

Most efficient way to empty an element with jQuery

In jQuery on October 9, 2011 by patrellery

There’s more than one way to empty an element with jQuery.

$(selector).html('');
$(selector).text('');

These are all valid but might not be as efficient as the empty() function.

$(selector).empty();

This is definitely the most clear way, and almost definitely the most efficient because by definition these call the empty() in their implementation. In addition, they invoke html parsers rather than just dealing with dom nodes like the other methods.

So go check your code now!

Articles

How to use jQuery to extract a URL parameter from a string

In jQuery on October 1, 2011 by patrellery

Many development languages, such as ASP, PHP, Python, Objective-C etc.., has their own function to parse and extract URLs components.

Where is the jQuery one? That will be very helpful if we don’t rely on the server to parse any URL and we let jQuery do it for us.

Read More »