jQuery Tricks and Tips Reference

In this post, we will discuss some quick tips and tricks which can help in writing a robust code using jQuery.

These jQuery tips are related to some basic methods using which we can resolve most encountered scenarios and problems.

Let’s check them out:

1) Check if Element is Hidden/ Shown using jQuery

To check if and the element is hidden or visible on the page, use the is() method. It can take several properties but to check visibility use :hidden or :visible as shown below:

2) If Checkbox/ Radio is Checked?

To check if a radio or checkbox is in selected/ unselected state we can use :checked argument in is() method:

3) Check if any form control is in the disabled or enabled state:

To check if a form control like select box, checkbox, radio, input is in enabled/ disabled state, use :disabled or :enabled argument in is() method:

4) Select All but not specific selector

To get all element but we don’t want some specific from them, then we can use the not() method as shown below:

Select all div elements but not with blue class:

5) Check if selector having a specific Class

To check if element having a specific or group of class we can use hasClass() method:

 

6) Get Selectbox Value and Option Text

To get dropdown selected value simply use val() method as shown below:

For getting the text of value selected in dropdown use text() method with find() as shown below:

for select box

 

 

Leave a Reply

avatar
  Subscribe  
Notify of