javascript - jQuery not working from onClick event -


for reason, jquery seems not working. have javascript function -- togaddcancel() -- called onclick attribute of input "btnaddcncl," , function designed toggle value of button. works fine without jquery, doesn't execute @ jquery. thoughts?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

without jquery:

function togaddcancel() {      var x = document.getelementbyid("btnaddcncl").value;     if (x=="add") {         document.getelementbyid("btnaddcncl").value = "cancel";     } else {         document.getelementbyid("btnaddcncl").value = "add";     }  } 

with jquery

function togaddcancel() {      var x = $('#btnaddcncl').val();     if (x=="add") {         $('#btnaddcncl').val("cancel");     } else {         $('#btnaddcncl').val("add");           } } 

togaddcancel() called from:

<cfinput type="button" id="btnaddcncl" name="btnaddcncl" onclick="togaddcancel()"> 

your script tag incorrect. try:

   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

edit

if typos cleaned , still doesn't work, can try using click() jquery:

$('#btnaddcncl').click(function() {     var x = $('#btnaddcncl').val();     if (x=="add") {         $('#btnaddcncl').val("cancel");     } else {         $('#btnaddcncl').val("add");           } }); 

no need onclick.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -