Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Modure Rares
Courses Plus Student 9,041 PointsWhy my js code runs first even if i place it at the bottom of the page???
I place my js code just before the </body> tag but it still runs before my page. Please help me.
Arturo Perez
Front End Web Development Techdegree Student 12,902 PointsShould be correct. make sure your saving your file before running it again.
We will be able to help more if you can show us your code.
Modure Rares
Courses Plus Student 9,041 PointsHow to get a image with the code ?
Modure Rares
Courses Plus Student 9,041 PointsI just typed "<script>...code...</script>" just before the </body> tag and it runs before the html
2 Answers
Arturo Perez
Front End Web Development Techdegree Student 12,902 PointsTry this
<script>
window.onload = function(){
// put your code inside of here
}
</script>
Liliana Brissos
7,686 PointsLike Arturo stated, use window.onload or if using jquery:
$(document).ready(function() {
// jQuery code goes here
});
Sergey Podgornyy
20,660 PointsYou wrote a commentm as if jQuery is not a JavaScript any more
jQuery is just a library which already has some functionality built on JavaScript, so that you can write native JavaScript code inside jQuery callbacks
jobbol
Full Stack JavaScript Techdegree Student 19,117 Pointsjobbol
Full Stack JavaScript Techdegree Student 19,117 PointsShow your code please.