jQuery quickies

Written on 8 May 2011, 11:13pm

Tagged with: ,

1. Get all the text input fields or textareas having IDs starting with a pattern

$('input, textarea').filter('[id^='+fieldID+']').each(function() 
{
	var field_value = this.value;
	var field_id = this.id;
	//do things here...
}

2. Add options to a select (in the example below – add the Google supported languages)

//Get the Languages array
	var languages = google.language.Languages;

	//populate the languages select
	$.each(languages, function(key, value)
		{   
		$('#my_select').
		append($("<option></option>").
		attr("value",value).
		text(key)); 
		}
	);

(more…)