Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove attribute in all children elements recursively

I have this html:

<tr id="Estuches_1">
    <td>
        <div class="group">
            <input name="VariableDataList[0].VariableDataForLevel[0].ProductionOrderId" id="VariableDataList_0__VariableDataForLevel_0__ProductionOrderId" >
            <input name="VariableDataList[0].VariableDataForLevel[0].AggregationLevelConfigurationId" id="VariableDataList_0__VariableDataForLevel_0__AggregationLevelConfigurationId">
            <select name="VariableDataList[0].VariableDataForLevel[0].VariableDataId" disabled="disabled" id="VariableDataList_0__VariableDataForLevel_0__VariableDataId">
                <option value="00">Serial Shipping Container Code(SSCC-18)</option>
                <option value="01" selected="">Global Trade Item Number</option>
                <option value="10">Batch or lot number</option>
                <option value="11">Production date(YYMMDD)</option>
                <option value="17">Expiration date(YYMMDD)</option>
                <option value="21">Serial number</option>
            </select>
        </div>
    </td>
    <td>
        <div class="group">
            <input name="VariableDataList[0].VariableDataForLevel[0].Value" disabled="disabled" id="VariableDataList_0__VariableDataForLevel_0__Value">
            <span class="field-validation-valid" data-valmsg-replace="true" data-valmsg-for="VariableDataList[0].VariableDataForLevel[0].Value"></span>
        </div>
    </td>
</tr>

In Javascript, I have a var named clone that create with the above html.

I want to remove the attribute disabled in all of the elements in the html (one in the select, and another one in the input text).

I have tried this:

var clone = $($.parseHTML(html));
clone.removeAttribute("disabled");

But it doesn't remove any of them. Maybe, because it is trying to remove the disabled attribute in the tr.

How can I remove the disabled attribute in all of the elements?

The id and the name of the elements will change.

like image 998
VansFannel Avatar asked Oct 30 '25 13:10

VansFannel


1 Answers

You need to target disabled element using .find() and then use .removeAttr() method

clone
    .find('[disabled]') //Target all disabled descendants 
    .removeAttr('disabled') //Remove disabled
like image 134
Satpal Avatar answered Nov 01 '25 01:11

Satpal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!