otester Posted August 5, 2010 Share Posted August 5, 2010 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 Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted August 5, 2010 Share Posted August 5, 2010 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? Quote Link to comment Share on other sites More sharing options...
otester Posted August 5, 2010 Author Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted August 5, 2010 Share Posted August 5, 2010 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(){ }); Quote Link to comment Share on other sites More sharing options...
otester Posted August 5, 2010 Author Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
ngreenwood6 Posted August 5, 2010 Share Posted August 5, 2010 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. Quote Link to comment Share on other sites More sharing options...
otester Posted August 6, 2010 Author Share Posted August 6, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.