i new jquery , having few issues. jsfiddle shows experiencing: http://jsfiddle.net/re2fh/5/ note how button nothing.
what trying set click listener button , have alert();. however, neither click event or alert() working.
i have tried click event .click(), .on(), .delegate(), , .live() none of seem work. alert, cannot find other equivalent "it automagically works if 'alert([sting]);'!" aware .click() 1.7+, .live() depreciated , .delegate() preferred on it.
in current project using jsp script <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> however, not work in jsfiddle either. version works fine on of our other pages (alert , .click events), reason 1 i'm working on has issues. have done can see emulate other pages well, may missing something. guy wrote jquery no longer our company.
i have searched so, , none of these results have worked me:
jquery .click() not functioning
jquery button not respond click method
+others along same lines.
any insight appreciated.
you had several issues. make sure check javascript console errors. here's working version:
$(document).ready(function(){ $(document).delegate('#but', 'click', buttonclick); function buttonclick() { $('#res').hide().html("button!!!").fadein('fast'); alert("hello!"); } }); to break down issues yours:
$(document).ready(function(){ $.delegate('#but', 'click', buttonclick()); function buttonclick(){ $('#res').hide().html("button!!!").fadein('fast'); alert("hello!"); }; // semi-colon shouldn't here }; // missing closing paren ready() delegate used this:
$('selector').delegate(...) though delegate() has been replaced on(), should used instead.
also, buttonclick() should buttonclick. when add parentheses, executing function. want in case pass function parameter.
Comments
Post a Comment