InterviewSolution
| 1. |
How Do I Test Whether An Element Has A Particular Class? |
|
Answer» * You can use the is() method along with an APPROPRIATE selector if ( $(‘#myDiv’).is(‘.PRETTY’) ) $(‘#myDiv’).show(); NOTE that this method ALLOWS you to test for other things as well. For example, you can test whether an element is hidden (by using the custom :hidden selector): if ( $(‘#myDiv’).is(‘:hidden’) ) $(‘#myDiv’).show(); * You can use the is() method along with an appropriate selector if ( $(‘#myDiv’).is(‘.pretty’) ) $(‘#myDiv’).show(); Note that this method allows you to test for other things as well. For example, you can test whether an element is hidden (by using the custom :hidden selector): if ( $(‘#myDiv’).is(‘:hidden’) ) $(‘#myDiv’).show(); |
|