This forum is now read-only. Please use our new forums at discuss.codecademy.com.

459 points
55d458559113cb2fd6000244_719622448
Submitted by
Shayan Al.
about 4 years ago

Why putting <script>'s links at the end of the body ?

Why we don't just put them in ?
$(document).ready() makes it load at last, when elements loaded completely, so i guess there is no difference where to put the s...


0 votes

permalink

3701 points
5334fc819c4e9db930001a0d_32139218
Submitted by
Leon
about 4 years ago


0 votes

permalink

++ general search
Did you try...
http://www.codecademy.com/guidance/choose

google search
== the Book ==
jquery [your question] site:developer.mozilla.org
CSS [your question] site:developer.mozilla.org
javascript [your question] site:developer.mozilla.org
[your question] site:jquery.com
[your question] site:getbootstrap.com

== discussions / opinions ==
jquery [your question] site:stackoverflow.com
CSS [your question] site:stackoverflow.com
javascript [your question] site:stackoverflow.com

== guidance ==
www.crockford.com
[your question] site:crockford.com

http://stackoverflow.com/questions/1795438/load-and-execution-sequence-of-a-web-page
https://learn.jquery.com/events/event-delegation/

https://developer.mozilla.org/en-US/Learn/HTML/HTML_tags
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference
https://developer.mozilla.org/en-US/docs/Web/CSS/Specificity
https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
http://www.w3schools.com/jquery/jquery_ref_selectors.asp

3701 points
5334fc819c4e9db930001a0d_32139218
Submitted by
Leon
about 4 years ago


0 votes

permalink

+++++ DOM representation of push menu

If your HTML-page is loaded into memory by the Browser
the memory-layout will be build
using the rules, as defined in the Document Object Model
in short the DOM

The DOM representation of the index.html file would look like:

               html
                |
         |------+---------|
         |                |
        head             body
         |                |
    |----+----|      |----+-----------|
    |    |    |      |                |
   link link link  10div(.menu)     27div(.jumbotron)
                    |                 |
     |--------------+----|          29div(.icon-menu)
     |                   |             |
   13div(.icon-close)  18ul          30i (.fa
     |                   |             |  and .fa-bars)
    img       |-----|----+|-----|    text  
              |     |     |     |    node
             19li  20li  21li  22li
              |     |     |     |
              a     a     a     a
              |     |     |     |
            text   text  text  text
            node   node  node  node

Now if you look at the DOM representation
the body-Tag is parent to
a 10div Element's Tree ( with class-attribute with class-name "menu" )
and
a 27div Element's Tree ( with class-attr. with class-name "jumbotron" set )

Now if you look in the style.css file,
with which you manage the Display of your Elements,
you will find that
the body object has the property left: 0; being set
( the body-Tree has a _start-Display at position left-0 )_

but
the .menu object has the property left: -285px; being set
and therefor the 10div-Tree is outside of Display.

In your 'app.js' file you are
CREATING a VARIABLE main
to which you assign a so-called anonymous Function
and in the FUNCTION-BODY of this anonymous Function
we are attaching our click Event-handlers
to the HTML-Elements which are
-1 carrying the "icon-menu" class-name as class-attribute
-2 carrying the "icon-close" class-name as class-attribute
( during the assignment the function is NOT executed )

You will have to add the code-line
$(document).ready( main );
which will result in the =main= Function to be executed
AFTER the Browser has set the ready Event-flag.

3701 points
5334fc819c4e9db930001a0d_32139218
Submitted by
Leon
about 4 years ago