Jump to content

jQuery button not working


otester

Recommended Posts

Currently trying to get a button on the page to call a jQuery function, I checked the W3schools callback functions section and I can't see why it won't work.

 

The function is set to load when the page does (gets data from a MySQL database, I need the button to refresh it), which it does. When I click the button nothing happens.

 

Page code:

 

<button type='button' id='gen_new'>Generate a new character!</button>

 

 

Js:

 

$(document).ready(function(){
$('#gen_new').click(function() {
	loadPCG();							
});
});

 

 

Any help would be grately appreciated!

 

 

Thanks,

 

otester

Link to comment
Share on other sites

Do you have the jquery library loaded? Are you clicking the button (you have the function set to click)? Did you try putting an alert or log statement inside of the click function to see if it is running?

 

Yes the jQuery library is loaded and all other jQuery stuff (slideshow, chat) works.

 

Also I tried sticking an alert function in:

 

$(document).ready(function(){
$('#gen_new').click(function() {
	//loadPCG();
	alert("The paragraph is now hidden");							
});
});

 

It did nothing again.

 

By the way I do have another "$(document).ready(" bit if this changes anything.

Link to comment
Share on other sites

You can have multiple document readys on the same page it does not matter. Is there another library loaded (prototype, scriptaculous, etc)? If so you will have to put jquery in no conflict mode. Something like this:

 

var $j = jQuery.noConflict();
$j(document).ready(function(){
});

Link to comment
Share on other sites

You can have multiple document readys on the same page it does not matter. Is there another library loaded (prototype, scriptaculous, etc)? If so you will have to put jquery in no conflict mode. Something like this:

 

var $j = jQuery.noConflict();
$j(document).ready(function(){
});

 

I don't have any other libraries loaded, only jQuery.

 

I tried your code anyways:

 

var $j = jQuery.noConflict();
$j(document).ready(function(){
$('#gen_new').click(function() {
	//loadPCG();
	alert("The paragraph is now hidden");							
});						
});

 

Still nothing.

Link to comment
Share on other sites

You have to use that variable everywhere like this:

 

var $j = jQuery.noConflict();
$j(document).ready(function(){
   $l('#gen_new').click(function() {
      //loadPCG();
      alert("The paragraph is now hidden");                     
   });                  
});

 

If that isnt the issue then idk without looking at it because your code looks correct for the element that you showed me. If you have firebug for firefox you can look at the console when the page loads or you click on the item to see if you have any errors and if so you can post it here and I can help.

Link to comment
Share on other sites

You have to use that variable everywhere like this:

 

var $j = jQuery.noConflict();
$j(document).ready(function(){
   $l('#gen_new').click(function() {
      //loadPCG();
      alert("The paragraph is now hidden");                     
   });                  
});

 

If that isnt the issue then idk without looking at it because your code looks correct for the element that you showed me. If you have firebug for firefox you can look at the console when the page loads or you click on the item to see if you have any errors and if so you can post it here and I can help.

 

I tried it with firebug and nothing shows up in the console, my chat buttons does though (which works).

 

Been working on my site for over 12 hours straight now, got to beat this thing before 3am!

 

Thanks trying so far thought if you can't think of anything else.

 

 

EDIT: Turns out that it doesn't like php echo-ed buttons, only normally-created ones, tried the same jQuery code but added a button to a test page it works, looks like I'll have to work round this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.