<< Back to article

jQuery with asp.net examples : Selector Sample


Select input box value:

Input box with id "txtName" :

Click Here to alert value selected from input box with id : "txtName"

Code:
alert('Hello ' + $('#txtName').val() + ' !!');

Select dropdown box value:

Dropdown box with id "drpGender" :

Click Here to alert value selected from dropdown box with id : "drpGender"

Code:
alert($('#drpGender').val());

Click Here to alert text selected from dropdown box with id : "drpGender"

Code:
alert($('#drpGender>option:selected').text());

Select divs using class name, and add class name to selected elements

1
2
3
4
5

Click Here to add another class "divChanged" to all elements with class name "divSample"
Code:
$('.divSample').addClass('divChanged');

Click Here to add remove class "divChanged"
Code:
$('.divSample').removeClass('divChanged');

Select asp.net textbox value:

As we know asp.net assigns unique id to controls at page generation time.
jQuery's selector using attribute will help us to find out exact control
Here we have asp.net textbox with id : "txtServerTextBox"

Click Here to alert value selected from input box with id : "txtName"

Code:
alert('Hello ' + $('input[id$="txtServerTextBox"]').val() + ' !!');
Please visit http://docs.jquery.com/Selectors for more details.

For more information:


<< Back to article