javascript - Avoid triggering multiple click events -


i'm trying make input field disabled/enabled when click on sibling link.

here code.

$('a').on('click',function(){     var inp=$(this).siblings('input');     inp.prop('disabled', false);     $(this).click(function(){         inp.prop('disabled', true);     }); }); 

when click first time works fine, next time won't work. because both click functions, triggers. i'm unable overcome issue. please me.

see fiddle.

just negate disabled prop on every click. elem.disabled = ! elem.disabled.

demo fiddle: http://jsfiddle.net/abhitalks/2a2ajbnb/1/

snippet:

$('a').on('click',function(){      var $inp = $(this).siblings('input');      $inp.prop('disabled', !$inp.prop('disabled'));  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <input type="text" name="x" value="22" disabled/><a href="#">change</a>


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -