Welcome Guest, Not a member yet? Register   Sign In
Jquery not working
#1

[eluser]Aniket Pant[/eluser]
I am trying to run a script in my view.

I am not able to autoload the jquery library, so i manually linked it to the jquery.js file.

But my script is not running.

I get an error in my firebug console saying that $ is not defined.

First i thought that the jquery file was not loading, but it is.

Need help. I am like stuck with my project as of now because of this. :|
#2

[eluser]tomcode[/eluser]
You might call $ before it's loaded and initialized
#3

[eluser]Aniket Pant[/eluser]
That is not working :|

I have tried that and I am not able to get the reason why $ is not initialized :|
#4

[eluser]tomcode[/eluser]
Post Your code
#5

[eluser]Aniket Pant[/eluser]
In header.php

Code:
<script href="<?php echo base_url(); ?>public/js/jquery.js" type="text/javascript"></script>

In the view, i have a div with id = "gym"

Code:
[removed]
$(document).ready(function() {
$("#gym").hide();
});
[removed]

This script is not running even when i have the jquery file included.

I have even checked and the jquery.js file is accessible. It is placed in the root, along with application, system and index.file in a folder name "public"
#6

[eluser]tomcode[/eluser]
The code of the resulting HTML page would have been more helpful.

1. make sure the script tag loading jquery.js comes before the other script tag
2. check in the web console that jquery.js is actually loaded
#7

[eluser]Aniket Pant[/eluser]
I have done that.

Is their any configuration or library i need to use?
#8

[eluser]tomcode[/eluser]
Try replacing the jQuery onDomLoad with this :

Put this script tag in the HTML head
Code:
<script>
function gymHider() {
  $("#gym").hide();
}
</script>

And call the function when the DOM is loaded

Code:
<body onload="gymHider()">
#9

[eluser]Aniket Pant[/eluser]
Problem solved.

Very idiotic error by me.

Instead of

Code:
<script href="<?php echo base_url(); ?>public/js/jquery.js" type="text/javascript"></script>

It should have been

Code:
<script src="<?php echo base_url(); ?>public/js/jquery.js" type="text/javascript"></script>
#10

[eluser]tomcode[/eluser]
Oh yeah, I overlooked that one, too.




Theme © iAndrew 2016 - Forum software by © MyBB