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

[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.
#2

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

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

[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
#5

[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
#6

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

[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.
#8

[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
#9

[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!');
});
#10

[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




Theme © iAndrew 2016 - Forum software by © MyBB