Here is my problem: as title says, jQuery is working only when I put the scripts on the bottom of the body tag. When I put them in head they are not working. I am using just
if it works when the code is below body is that the items are already loaded, I do not know if you placed your code inside the jQuery ready function.
example:
$( document ).ready(function() {
$( "p" ).text( "The DOM is now loaded and can be manipulated." );
});
source: http://api.jquery.com/ready/
Thanks guys I found the solution for my problem , you guys are really awesome .. If anyone have same problem here is what i dd and it works ...
As @Jaimil Prajapati , @Damen Salvatore and @coder_ck said i just need to put my jquery code inside document ready function .. Here is what i put in head and now it works :)
<head>
<script type='text/javascript' src='jquery/js/jquery-1.10.2.js'></script>
<script type='text/javascript' src='jquery/js/jquery-ui-1.10.4.js'></script>
<script type='text/javascript' src='jquery/time/jquery.ui.timepicker.js'></script>
<script>
$(document).ready(function() {
console.log('jQuery is now ready to be executed!');
$('#date').datepicker({ dateFormat: 'dd/mm/yy'});
$('#time').timepicker();
$(function() {
$( document ).tooltip();
});
});
</script>
</head>
If someone was having the same issue, I solved it by setting the charset UTF8 when I added the jQuery lib, as below:
<script type="text/javascript" charset="utf8" src="../jquery-3.2.1.min.js" />
The way jQuery, or JavaScript for that matter, works is it detects elements or binds events at the time when the script itself is called. As the document is loaded from top to bottom, placing jQuery at the bottom makes sure your DOM is loaded first, before executing JS. On the other hand, you can place jQuery at top, using technique such as this:
$(document).ready(function() {
console.log('jQuery is now ready to be executed!');
// Place jQuery code here...
});
This is basically telling jQuery, wait until DOM is loaded, before acting upon it.
Source: http://api.jquery.com/ready/
i dont think your problem is where to load jquery, its how to use it for example put jquery in head and try this :
$(document).ready(function(){
alert('document is fully loaded and jquery can access all elements now !');
})