I have a hypothetical question, something where by knowledge is a wee bit fuzzy.
If I have a jquery object: Common.$footer = $('.footer');
And I declare it when the footer doesn’t exist, but then the footer gets added later, will the reference work then?
Or a similar scenario if I have did the same when the footer was showing, then it removed, and I used it.
I’m wondering if its ok to setup some references early on in my code, that I can use just later and test if object exists with:
Common.$footer[0] && MyFuncCall();
Also, if I add a element in later on, is it ok to just grab it with $(‘.my-dynmically-added-el’) ? or do I need to use .live or something?
There are no references. Anyway…
$(selector)returns a fixed set of elements that currently match the selector.If this result is empty then, it will always be empty: the resulting jQuery objects can — and should — be considered immutable, even if the elements they represent can be mutated.
Thus:
There is
live(), but that is different.Happy coding.