jQuery: Check if Element has Class - hasClass() Method Example
To check if an element with the ID "qcart" has the class "q_payment_section" using jQuery, you can use the .hasClass() method. Here's an example:
if ($('#qcart').hasClass('q_payment_section')) {
// The element with ID \"qcart\" has the class \"q_payment_section\"
// Perform actions here
} else {
// The element with ID \"qcart\" does not have the class \"q_payment_section\"
// Perform other actions here
}
In this example, $('#qcart') selects the element with the ID "qcart" and .hasClass('q_payment_section') checks if it has the class "q_payment_section.
原文地址: https://www.cveoy.top/t/topic/p6T0 著作权归作者所有。请勿转载和采集!