Use the .length
property of the jQuery collection returned by your selector. To check if a div
element with the ID of myDiv
exists:
if ( $( "#myDiv" ).length ) {
alert('It exists!');
}
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.