3
Why is that,
if (typeof($("div#elementoquenãoexiste")) !== "undefined") { console.log("existe"); }
returns "existe"
in the logs? Should not return undefined
, taking into account that the element the selector indicates does not exist?
Or is it that being involved in a function of jQuery ($()
) it comes to be defined since it has functions/properties attached to it, even if the selector points to an element that does not exist in the DOM. I’m sure?
I need a proper sense of what’s going on in this case, thank you!
I think you want to do
if ($("div#elementoquenãoexiste").length) { console.log("existe"); }
– Sergio