Also, keep in mind that in many cases, you do not need to check for the existence of something as you might if you were using straight up JS. If you try to run a jQuery method on an empty jQuery object, it will not error. For example:
$("#mydiv").show(); If #mydiv is not found, the jQuery object will be empty, and show() will not execute. -- Josh ----- Original Message ----- From: Karl Swedberg To: jquery-en@googlegroups.com Sent: Friday, November 02, 2007 11:52 AM Subject: [jQuery] Re: Performing a function if an element is present Hi Ezra, This is the perfect place for such questions. You can test for the existence of an element like this (for example): if ( $('#someid').length ) { // do your thing ... } --Karl _________________ Karl Swedberg www.englishrules.com www.learningjquery.com On Nov 2, 2007, at 1:50 PM, Ezra B. Gildesgame wrote: Hello, I'm getting started with jQuery and have read several tutorials, but would appreciate clarification: How can I create a simple conditional statement to check for the presence of a certain element on a page, such as an anchor with a certain class or id, and then perform a function? I hope that this is an appropriate place to ask this question. If it is not, I would appreciate any direction as to where might be more appropriate. Thank you! Ezra Gildesgame