mardi 30 août 2016

jQuery - Check and uncheck the 2nd checkbox when first clicked using name attribute

I am trying to check the 2nd checkobx (Delete it!) automatically, when first one (Hide it) is clicked? System generated html doesn't contain any id or class for the checkbox elements. I tried to target the name attribute, but it failed every time.

HTML

<fieldset class="es-el eddhd">
    <div class="es-label">
        <label for="es-eddhd">Hide it</label>
        <br>
    </div>
    <div class="es-fields">
        <span data-required="no" data-type="radio"></span>
        <label>
            <input name="eddhd[]" value="Yes" type="checkbox"> Yes
        </label>
    </div>
</fieldset>
<fieldset class="es-el eddhrd">
    <div class="es-label">
        <label for="es-eddhrd">Delete it!</label>
        <br>
    </div>
    <div class="es-fields">
        <span data-required="no" data-type="radio"></span>
    <label>
        <input name="eddhrd[]" value="Yes" type="checkbox"> Yes
    </label>
    </div>
</fieldset>

jQuery

jQuery(document).ready(function($){
    $("input:checkbox[name='eddhd']").click(function() {
        $(this).parents('.eddhrd::nth-child(2))').siblings("input:checkbox[name='eddhrd']").find('input:checkbox').attr("checked","checked");
    });
});




Aucun commentaire:

Enregistrer un commentaire