Ask Question Forum:
Model Library:2025-02-08 Updated:A.I. model is online for auto reply question page
C
O
M
P
U
T
E
R
2
8
Show
#
ASK
RECENT
←
- Underline
- Bold
- Italic
- Indent
- Step
- Bullet
- Quote
- Cut
- Copy
- Paste
- Table
- Spelling
- Find & Replace
- Undo
- Redo
- Link
- Attach
- Clear
- Code
Below area will not be traslated by Google,you can input code or other languages
Hint:If find spelling error, You need to correct it,1 by 1 or ignore it (code area won't be checked).
X-position of the mouse cursor
Y-position of the mouse cursor
Y-position of the mouse cursor
Testcursor
caretPos
Attachment:===
Asked by brgdotnet
at 2024-07-23 22:07:22
Point:160 Replies:9 POST_ID:829085USER_ID:10
Topic:
jQuery;;
In JQuery,
is $(document).ready(function() the same as $(function () { }
is $(document).ready(function() the same as $(function () { }
Expert: Rob Jurd replied at 2024-07-27 19:11:32
To clarify,
$(document).ready(function() {}); is capturing the "ready" event when the document had loaded.
$(function() {}); is passing an anonymous function to the jQuery class. JQuery is configured such that the anonymous function is only called once the DOM has loaded.
More info on frameworks here:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_12264-Javascript-Frameworks-what-are-they.html
And JavaScript objects (that is all jQuery is)
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_13138-Javascript-is-just-an-Object.html
$(document).ready(function() {}); is capturing the "ready" event when the document had loaded.
$(function() {}); is passing an anonymous function to the jQuery class. JQuery is configured such that the anonymous function is only called once the DOM has loaded.
More info on frameworks here:
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_12264-Javascript-Frameworks-what-are-they.html
And JavaScript objects (that is all jQuery is)
http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_13138-Javascript-is-just-an-Object.html
Expert: eenookami replied at 2024-07-27 18:52:51
Force accept. There is no difference between the two. One is short hand for the other
Expert: duncanb7 replied at 2024-07-24 02:57:26
Thanks for your reply , please review my post I didn't suggest anything and I just verify it by testing for all of you from your previous post to me.
The answer is Yes to the question and mentioned at this site
http://learn.jquery.com/using-jquery-core/document-ready/
Duncan
The answer is Yes to the question and mentioned at this site
http://learn.jquery.com/using-jquery-core/document-ready/
Duncan
Expert: Scott Fell (padas) replied at 2024-07-24 02:55:47
Thank you Duncan. Your description matched something for pure javascript. If you add the $ or jquery in front, now you are talking about jquery as you suggest, but then the description you gave is incorrect.
The simple correct answer to the question,
Yes, they are both the same.
The simple correct answer to the question,
is $(document).ready(function() the same as $(function () {
Yes, they are both the same.
Expert: duncanb7 replied at 2024-07-24 02:50:39
Scott, you agree ?
Expert: duncanb7 replied at 2024-07-24 02:42:53
Scott, you are correct and I miss $
And the article mention $(function()) is shorthand for $( document ).ready() at this site. http://learn.jquery.com/using-jquery-core/document-ready/
And my previous post is shown the different between $(document.)ready() and (function()) , javascript self-start function only.
You can test from the following code , if the div tag change color means it work for the code. Finally, it showed only Self-javascript function can not change to green color.
Duncan
And the article mention $(function()) is shorthand for $( document ).ready() at this site. http://learn.jquery.com/using-jquery-core/document-ready/
And my previous post is shown the different between $(document.)ready() and (function()) , javascript self-start function only.
You can test from the following code , if the div tag change color means it work for the code. Finally, it showed only Self-javascript function can not change to green color.
Duncan
<html><meta http-equiv="Content-Type" content="text/html; charset=Big5"><head><title>Title</title><style></style><script src="/js/jquery.min.js" type="text/javascript"></script><script src="/js/jquery-ui.min.js" type="text/javascript"></script><script type="text/javascript">(function() { document.getElementsByClassName('tap')[0].style.color="Green";});$(function() { document.getElementsByClassName('tap')[1].style.color="Green";});$(document).ready(function() {document.getElementsByClassName('tap')[2].style.color="Green";});</script><script type="text/javascript"></script></head><body ><div class="tap">Self-javascript</div><div class="tap">$(function())</div><div class="tap">Ready-jquery</div></body></html> 1:2:3:4:5:6:7:8:9:10:11:12:13:14:15:16:17:18:19:20:21:22:23:24:25:26:27:28:29:
Expert: Scott Fell (padas) replied at 2024-07-24 01:50:39
@duncanb7, I'm just trying to double check because we seem to have different answers for the same thing.
I may be confused, but are you talking about pure javascript? or jquery?
self calling anonymous function that is just function, it will operate or start as soon as possible when the browser is interpreting your ecma-/javascript
I may be confused, but are you talking about pure javascript? or jquery?
Accepted Solution
Expert: Scott Fell (padas) replied at 2024-07-24 00:31:20
160 points EXCELLENT
These two sets of code below are the same http://api.jquery.com/ready/. I personally use the later because it is faster to type out.
Expert: duncanb7 replied at 2024-07-23 23:19:35
There is different between
At $(document).ready(function(),
The function() will operate after the whole page is completely loaded and DOM is ready.
But
$(function () { }
is self-start or self calling anonymous function that is just function, it will operate or start as soon as possible when the browser is interpreting your ecma-/javascript regardless the page being loaded completely or not
Duncan
At $(document).ready(function(),
The function() will operate after the whole page is completely loaded and DOM is ready.
But
$(function () { }
is self-start or self calling anonymous function that is just function, it will operate or start as soon as possible when the browser is interpreting your ecma-/javascript regardless the page being loaded completely or not
Duncan