Thursday, January 5, 2012

JQuery Tutorial 1

In this section we are going to see some selector in jquery...

selector means, if you want to access group of elements together (like list of checkbox,radio buttons,etc) you can use selector in jquey. with very minimum code you can access all the elements using ids , names or without anything.

For example :
i am having more than 10 or 100 checkboxs in my form.i have to access all the checkbox value which are checked with minimum code and without any id or name...

code :

$('input[type=checkbox]').each(function () {               
        if(this.checked){
            alert(this.val());
        }
});

like this if you having two group of checboxs. for example 10 checkbox with one name and another 10 checkbox with another name. so if you want to access checkbox checked in the first 10 checkbox value. in the above example you can access all the checkbox in form. but u cant access particular checkbox with same name. so for that you have to use below code...

code :
$('input:checkbox[name=checkbox_name]').each(function () {               
        if(this.checked){
           alert(this.val());                
        }
    });

we will discuss this in next section with more intresting things... thanks for reading....