Not sure why the code below isn't working... I've tried a number of variations:
$('button.mytestbutton').live('click', function() ...
$('button.mytestbutton').bind('click', function() ...
$('button.mytestbutton').click(functi开发者_开发知识库on() ...
etc., etc. I've also tried inserting return false; before the closing });
In firebug, I don't get anything at all in the console. Absolutely no indication that it's been clicked at all... Is there something about "button" that prevents me from doing this?
Here's the current jquery iteration:
$('button.mytestbutton').live('click', function() {
$('#progress').append('Ok, I clicked it.');
return false;
});
Here's the HTML:
<button class="mytestbutton">Test</button>
<div id="progress"></div>
I also don't see any errors in Firebug on initial page load, and when I check the <script></script>
tags, I see the js there... Not sure where to go from here...
Make sure your events are attached after the DOM is fully loaded.
$(function(){
// event binding code can go here.
});
This is an equivelent to $(document).ready(function(){});
I did it here: http://jsfiddle.net/8y7Aw/ and it worked perfectly fine. Could there be other JavaScript or HTML IDs that are preventing the action from going? It even works when I use .click
instead of .live
.
just use $('button.mytestbutton').click();
(don't declare a new function within click(). that overides the first one)
EDIT:
unless I completely missunderstood you :P
Its is maybe an error on another part of your script... It happend to me too, without firebug error, you have to check all of your js code
精彩评论