Skip to main content

Posts

Showing posts with the label disable

How to disable/enable an element with jQuery or Javascript

jQuery Sometimes you need to disable/enable the form element like input or textarea. Jquery helps you to easily make this with setting disabled attribute to "disabled". For e.g.: //To disable  $( '.someElement' ).attr( 'disabled' , 'disabled' ); To enable disabled element you need to remove "disabled" attribute from this element or empty it's string. For e.g: //To enable  $( '.someElement' ).removeAttr( 'disabled' ); // OR you can set attr to ""  $( '.someElement' ).attr( 'disabled' , '' ); Javascript My case was a bit different. I had to disable simple control element used without a form. < a   class = "rotator"   href = ""   onclick = "return rotate(this, parameter, url)"   > I made a javascript like this: /** script */ var  disabled =  false ; function  rotate(button, parameter, url) {      if  (disabled)          return   false ;     d...