I was going to do $("#foo") !== null
to assert that an element with the id="foo"
does exist in the page, but it turns out even if the element doesn't exist, the selector $("#foo")
still returns an object.
So to test whether the selector can find an element, should
assert($("#foo").length >= 1);
be used? I also thought of using assert($("#foo").is("div")
but if the HTML is changed, and the element is not a div
but becomes a p
or span
, then it will break the assert. What is a good, standard way to assert that the element does exist?
jsfiddle sample: http://jsfiddle.net/qnbAn/1/