Categories

.toggleProp()

Categories: Attributes

.toggleProp( propertyName, value, [ alternateValue ] )Returns: jQuery

Plugin: jQuery.fn.prop

Description: Add or remove a property from each element in the set of matched elements.

  • .toggleProp( propertyName, value, [ alternateValue ] )

    version added: 1.0

    propertyName   The name of the property to toggle.

    value   A value to be toggled for each element in the matched set.

    alternateValue   A value to be set for each element in the matched set for preventing remove the property.

This method take property name and value as its parameter. If the value of the named property for the matched element the same as the givn value, the property will removed or replaced with the alternateValue.

  • Toggle property name for all input elements.

    HTML:
    <div>
      <input type="text" name="A" disabled="disabled"/>
      <input type="text" name="C" disabled="disabled"/>
      <input type="text" name="B"/>
    </div>
    Code:
    $('input').toggleProp( 'disabled', true );
    Results:
    <div>
      <input type="text" name="A"/>
      <input type="text" name="B"/>
      <input type="text" name="C" disabled="disabled"/>
    </div>