If you want to keep performance, maybe it's better to do: if( $("#myid").is('div.myclass')) alert("YEAH, WE GOT IT"); else alert("Ha, my ID is misused!!");
Wow. When I started writing this reply, I thought of using tagName and className, but is() is so much more elegant. Christof Donat wrote: > Hi, > > >> ID should be uniqe over the page, so div#myid is redundant. >> > > No, it isn't. It should return an empty jQuery-Object in case the Element > with > the id "myid" is not a div. That is usefull when you produce your Content > dynamically (e.g. with PHP). The same is true for .myclass#myid, or even > div.myclass#myid which should return the element with the id "myid" only if > it is a div and has the class "myclass": > > if( $("div.myclass#myid").length > 0 ) alert("YEAH, WE GOT IT"); > else if( $("#myid").length > 0 ) alert("Ha, my ID is misused!!"); > > Christof > > _______________________________________________ jQuery mailing list discuss@jquery.com http://jquery.com/discuss/