Check if a jquery object has a particular class/id

Snippet

Use is() to check if a class exists on a jQuery element.

if ($(#elm).is('.checkthisclass')) { 
 // #elm has the class
} else { 
 //#elm doesn't have the class
}

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.