InterviewSolution
| 1. |
How Can An Element Be Checked If It Contains A Specific Class? |
|
Answer» The hasClass method DEFINED can be used to check if an ELEMENT actually contains the specified class. For example: usage of the hasClass: $("div").click(function(){if ( $(this).hasClass("PROTECTED") ) $(this) .animate({ left: -10 }) .animate({ left: 10 }) .animate({ left: -10 }) .animate({ left: 10 }) .animate({ left: 0 }); }); The is() method can also be used with a SELECTOR for a more advanced level of matching. For example: if ( $('#myDiv').is('.pretty.awesome') ) $('#myDiv').show();This method can be used to test various other things, such as it could be used to detect if the specified element is hidden or not. The hasClass method defined can be used to check if an element actually contains the specified class. For example: usage of the hasClass: The is() method can also be used with a selector for a more advanced level of matching. For example: This method can be used to test various other things, such as it could be used to detect if the specified element is hidden or not. |
|