Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I remove an attribute of all children?

I have a cloned div containing input elements, all of which are disabled. I am trying to use the following JQuery code to remove the disabled attribute of each of the div's children.

clonedElement.children().removeAttr('disabled');

I do not have a ton of JQuery experience, so I am probably misunderstanding the way this is supposed to work. How should I be going about removing the "disabled" attribute from all children of the cloned node?

If it helps, clonedElement was created with the JQuery .clone() method.

HTML I AM USING TO TEST---

        <div id="original_item" class="hidden">
            <div class="row_submit">
                <div class="med_field">
                    <p>Product:</p>
                    <select name="product[]">
                        <option></option>
                    </select>
                </div>
                <div class="small_field">
                    <p>Type:</p>
                    <select name="type[]">
                        <option></option>
                    </select>
                </div>
                <div class="small_field">
                    <p>Price:</p>
                    <input type="text" name="price[]" value="test" disabled="disabled" />
                </div>
                <div class="small_field">
                    <p>Quantity:</p>
                    <input type="text" name="quantity[]" />
                </div>
                <img onclick="removeItem(this);" title="Remove Item" style="margin: 18px 0 0 12px;" src="icons/cancel.gif" />
            </div>
            <input type="hidden" name="warehouse_data[]" />
        </div>
like image 772
dqhendricks Avatar asked Dec 27 '22 19:12

dqhendricks


1 Answers

children only looks in immediate children and if the clonedElement is not one of med_field/small-field then it would not work.

You can use find() instead to search for elements beyond immediate children.

i.e.

//for jQuery < 1.6
$("*", clonedElement).removeAttr("disabled");
//or
clonedElement.find("*").removeAttr("disabled");

//for jQuery >= 1.6
$("*", clonedElement).removeProp("disabled");
//or
clonedElement.find("*").removeProp("disabled");
like image 179
Chandu Avatar answered Jan 10 '23 02:01

Chandu