Check if Element Exists in JQuery
Sometimes we come across a situation where we want to find if element exists in jquery. how can we Check if element exists jQuery? there is no such function available in jQuery but there is a simple way to check it. if($("#testElement").length){ //element exists code goes here alert("Element exists"); } else{ //element doesn't exist code goes here alert("Element doesn't exist"); } How did it work?? Reason is simple! jQuery will always provide you return object which has length property irrespective …