問題:
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?也許是插件或功能?