问题:
How can I check the existence of an element in jQuery?如何检查jQuery中元素的存在?
The current code that I have is this:我目前的代码是这样的:
if ($(selector).length > 0) {
// Do something
}
Is there a more elegant way to approach this?有没有更优雅的方法来解决这个问题? Perhaps a plugin or a function?也许是插件或功能?