Assigning before $(document).ready
Hi,
I saw this code:
- var $element = $('#element');
-
- $(document).ready(function()
- {
- console.log($element);
- });
If I understand this correctly above statement will work in most cases, but it's not 100% sure since DOM might not be loaded yet.
This would be the better way, right?
- var $element;
-
- $(document).ready(function()
- {
- $element = $('#element');
- console.log($element);
- });
I just want confirmation that the first example might not always work.
Thanks in advance!