jQuery Element exists function

Hello, So  a friend of mine asked me a question that if there is a function in jQuery that makes it simple to check if a element with an ID exist in DOM or not. So I think that function does not exist but its pretty simple to write one. Ok first things first, here is a simple way to check if an element exist or not. Markup Here is an example markup on which our jQuery code will be based on [crayon-61afb1d32a030687175223/]  A simple check (This is how you do it anyway) [crayon-61afb1d32a038320606898/] So above works pretty well and it will work pretty well with the CSS class selectors too. But just if you are after exists() function here is what you can do :) The only advantage is readability of your code. Now lets write a little plugin so that you can hook it in your code easily [crayon-61afb1d32a039650293174/]     So to be generic in nature here is a generic definition for our exists() function for jQuery [crayon-61afb1d32a03a969616717/] [crayon-61afb1d32a03b472850155/] To make our function return boolean true or false we just need to change the condition in our plugin function as shown below [crayon-61afb1d32a03c936488720/] I hope that this helps. If you would like to add something or make a correction please leave your comments Cheers     … [Read more...]