jQuery – Playground

jQuery makes playing with the DOM elements so easy and concise that its just not possible to think of any other approach.

So as an example, if I wanted to select all  checked radio buttons  with their ids starting with ‘spec’ with value = ‘no’

$(":input[id^='spec'][value='no']:radio:checked")

For text fields, the usual way to access the value is

$('#spec_identifier').val()

But in case of a textarea, it changes to

$('textarea#spec_description').val()

Some more examples

$('select.foo option:selected').val();    // value from a dropdown select
$('select.foo').val();                    // value from a dropdown select even easier
$('input:checkbox:checked').val();        // value from a checked checkbox
$('input:radio[name=bar]:checked').val(); // value from a set of radio buttons

jQuery keeps your code tidy and concise retaining readability.

Advertisements

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