以下是检测一个元素是否含有一个redColor类的例子,含有时,则把其类变为blueColor。 <html> <head> <styletype="text/css"> .redColor { background:red; } .blueColor { background:blue; } </style> <scripttype="text/javascript"src="jquery-1.3.2.min.js"></script> </head> <body> <h1>jQuery check if an element has a certain class</h1>
<divclass="redColor">This is a div tag with class name of "redColor"</div>