score:0
In your case you do not need to wait due to the location of your script. The script wont be parsed/executed till the elements above it are parsed. Therefore, it's safe to assume the contentMain div and it's descendants are ready to be manipulated.
{%include file='/var/www/include/tpl/header.tpl'%}
<div id="contentMain">
<h1>{%$heading%}</h1>
{%if isset($Details)%}
<h4>Details</h4>
{%$Details%}
{%/if%}
{%$table%}
</div>
<div id="space">
</div>
<script>
alert("It worked!");
//run some stuff here
</script>
{%include file='/var/www/include/tpl/footer.tpl'%}
score:0
You can do this using jquery's document.ready.
On the header, Include jquery reference.
<script type="text/javascript">
$(document).ready(function() {
alert("It worked!");
});
</script>
</head>
score:3
jQuery has a handy-dandy little function that you can attach to the document to run functions once the body has loaded. It is the ready function.
$(document).ready(function() {
//Place code here to do stuff
});
Doing it this way, you can ensure that the body and all of its content has loaded before any of the stuff inside of the function runs.
Related Query
- Run jquery Once content of a div has fully loaded
- jQuery slideUp doesn't work within ajax div that has loaded with slideDown
- jquery - how to continue the execution of one function once another function has returned a value
- Make jQuery plugin method publicly available once the plugin has been applied to an element
- Need help in running Javascript on a page loaded using jquery mobile changePage function
- manipulating form field values with jQuery that has had the form loaded into the DOM
- Apache Wicket and jQuery JavaScript in head section only loaded once
- jquery buttons - hidden divs get refreshed or loaded once they are shown
- JQuery Mobile getting loading animation to go away once content is loaded
- jQuery not running in ajax loaded modal until modal is resized
- jQuery call function after 'get' has loaded
- PHP jQuery AJAX....reload a drop-down once data has been submitted to DB
- Replace images and load once rest of document has been loaded
- jquery event handler only running once
- Change element of a modal once loaded - WP JS jQuery
- How to check jquery is working and Jquery.min.js file has loaded successfully
- Is there an event in an MVC 5 View or jquery raised when a partial view has been loaded and its elements are accessible
- Can't get jQuery script to run after page has been loaded
- Prevent Hover Function if Body has class in Jquery
- Delay function until image has loaded jquery
- jquery ajax php -problem with running jquery code more than once
- Unable to update SCRIPT inside DIV once page has loaded
- Unable to import Fancybox on Shopify site. Jquery loaded only once
- jQuery zclipboard Uncaught TypeError: Object [object HTMLAnchorElement] has no method 'data'
- random li (list) with jQuery before page get loaded
- How to check if a custom (pseudo) selector has been added to jQuery
- If jQuery has Class do this action
- Get the data that is being loaded by jquery in PHP CodeIgniter
- jQuery onClick only runs once on table cell
- JQuery UI Button Loaded On Ajax Not Styled
- jQuery Mobile - Enhancing & Binding to AJAX loaded HTML
- Using a jQuery custom scrollbar autoscrolls my body
- jQuery Selector for all items in body excluding items in specific parent
- php form action and jquery validation executing at once
- JS - jQuery - Tw Bootstrap - block user to scroll body but show scroll bars
- Refresh browser once when resizing past point - JQuery
- jQuery if element has class add class to 'this'
- HTML Breadcrumb Displaying Then Losing Location Once New Page Is Loaded
- How to display a table of items once I select a value from the first dropdownlist using MVC 4 jQuery and AJAX
- gettings values from checkbox group with jQuery only works once
- jQuery animate on click works once locally, but works multiple times in jsfiddle
- Why a JQuery function fires only once on the same page
- jQuery Mobile Popup position after user has scrolled
- how to run a javascript function loaded using jquery .load
- jQuery - how to assign click() to an element inside html that was loaded using load()
- Fire callback once jQuery while loop completes
- Object [object Object] has no method - jQuery error
- running Flask jQuery example under Apache proxy
- Jquery Ajax Call In For Loop Only Runs Once - Possible Issue with Timing & Exit Condition?
- jQuery UI Draggable with grid and containment has weird offset
More Query from same tag
- How to close jquery dialog inside Java code
- Can I run separate asp.net c# page load events using JQuery multipage/same file data-role=page?
- Empty Iframe from google maps on fancybox reopen?
- multi-container blueprint grid and drop down menu cut off because of it
- toggleClass not working
- Generating a barcode/qr code to contain a user ID
- Codeigniter form validation return false on ajax request
- Issue with jQuery waypoints after adding wrapping div
- I'm using jQuery How can I enable all keyboard keys when after i disable them?
- iFrame and Textarea Editor Live Preview and "Designer Mode" with activeElement
- jQuery - ForEach function on rendered HTML
- Jquery click event not working on newly added class
- Highlight the text
- jquery form validation is not workng
- Error in getting data from ajax json response
- How do I move a div from one page to another?
- How to store and get data from a json file with javascript?
- Unable to move scripts under standard_header_includes to footer in HubSpot
- jQuery hover animation
- Loaded header via PHP include and jQuery load overlaps the CSS for the main file
- jQuery: Array Breaks at Space
- jQuery calling Change Event with Trigger only fires once
- Ajax / Json How to run an INSERT/UPDATE into mysql
- Multiple CSS & jQuery-based dropdown menus remain open after clicking on another one
- Tables: selected rows and loop through column JQuery&JavaScript
- jQuery Draggable Inadvertently Gets Destroyed on "Out"
- Jquery Ajax Send multiple checkbox values to php
- Most Accurate jQuery Transition Time Translation Delay
- returning data async after jquery $.ajax post request in asp.net mvc
- ASP.Net MultiView & JQuery Accordion