CodeIgniter Forums
jQuery not working - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: jQuery not working (/showthread.php?tid=11214)

Pages: 1 2 3


jQuery not working - El Forum - 08-30-2008

[eluser]RaZoR LeGaCy[/eluser]
Hi all,

I put in the head tag. I
Code:
<  script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js" type="text/javascript"  ><  /  script  >

Then in body I put
Code:
<  script type="text/javascript"  >
if(jQuery) {
alert("Loaded");
}

$(document).ready(function() {
   $('a.test').click(function() {
     alert("Hello world!");
   });
});
<  /script  >
<div id="test" class="test">
<a href="" class="test" id="test">Link</a>
</div>

When I load the page it tells me that jQuery is loaded with a popup alert that I included.
When I click the link and it just reloads the page.

I can't see anything wrong.


Thanks all.


jQuery not working - El Forum - 08-30-2008

[eluser]Randy Casburn[/eluser]
Hi Razor, you've got two els with tje same Id. change 1 I bet things willbe brtter. Randy


jQuery not working - El Forum - 08-30-2008

[eluser]RaZoR LeGaCy[/eluser]
Exactly what should I change? Sorry for the slow response lol


jQuery not working - El Forum - 08-30-2008

[eluser]Bramme[/eluser]
Code:
&lt;  script type="text/javascript"  &gt;
if(jQuery) {
alert("Loaded");
}

$(document).ready(function() {
   $('a.test').click(function() {
     alert("Hello world!");
     return false;
   });
});
<  /script  >
<div id="test" class="test">
<a href="" class="test" id="test">Link</a>
</div>
Try that. Dunno if it'll work though


jQuery not working - El Forum - 08-30-2008

[eluser]Randy Casburn[/eluser]
Hi Razor,

I was on a plane and using my phone before. Now that I'm home and have had some dinner and can get back to you. Here is what you should change...

[quote author="RaZoR LeGaCy" date="1220136417"]
Code:
<div id="CALL_THIS_SOMETHING_ELSE" class="DONT_CARE">
<a href="&lth;javascript&gth;:void(0);" class="test" id="test">Link</a>
</div>
[/quote]

Try that and see what happens,

Randy


jQuery not working - El Forum - 08-30-2008

[eluser]RaZoR LeGaCy[/eluser]
it still just refreshes the page.


jQuery not working - El Forum - 08-30-2008

[eluser]RaZoR LeGaCy[/eluser]
I am thinking it is just mvc getting in the way.

Can someone post the controller and view for something this simple because I cannot get it to work in ci but plain html I can.


jQuery not working - El Forum - 08-30-2008

[eluser]Randy Casburn[/eluser]
I put your exact code into a fresh install of v1.6.3 of CodeIgniter and it worked perfectly. I don't think it is CI or "MVC" that is getting in your way.

Try it with a clean install.

You problem is not CI it is with something else in your configuration or a conflict someplace else.

Randy


jQuery not working - El Forum - 08-30-2008

[eluser]Colin Williams[/eluser]
Damn I hate when MVC screws with my JavaScript! :down:

Not sure where the problem is, RaZoR LeGaCy. Try putting an alert call in the ready callback function, and see if you get anything:

Code:
$(document).ready(
  function () {
    alert('The document is ready.');
  }
);

You can also shorten your code, for what it's worth:

Code:
$(function () {
  alert('This is shorter!');
});



jQuery not working - El Forum - 08-30-2008

[eluser]Randy Casburn[/eluser]
[quote author="Colin Williams" date="1220176647"]

You can also shorten your code, for what it's worth:

Code:
$(function () {
  alert('This is shorter!');
});
[/quote]

Not sure what you mean by this. He was constructing an event handler on the click event of the anchor tag with the id= 'test'

Written the way you have it, there is no event handler.

Randy