I'm using jQuery to add events to DOM elements. As I do this, I often times use selectors that technically could gather a list of matching items rather than just a single one. e.g. using the .children()
and .find()
methods I could find 0, 1 or many matching DOM elements.
Do I simply need to check .size() == 1
on every element as I attach events, or is there a simpler way to do this, e.g. a selector with an expected matches column that fails if that expected number is not equal to the size?
It seems silly I suppose, given that I also output the HTML and ought know the correct answer, but I have lots of DOM manipulations going on and was wondering if there's any kind of sanity checking mechanism built in or not.