0

When clicking on button #btn-modal-clear I would like to select and add a class to the li where it's sub-child input is empty (value=""). How do I do this?

html:

<li>...<li> 
<li>
    <a class="myCheckboxLink" tabindex="0">
        <span class="myCheckboxSpan">
            <i class="fa fa-check fa-check-checkbox" aria-hidden="true"></i>
        </span>
        <label class="radio">
            <input value="" type="radio">Name
        </label>
    </a>
</li>
<li>...<li>     

js:

$('#btn-modal-clear').on('click', function() {  
    $('.select-name').multiselect('select', ['']);
    $('.select-name').multiselect('updateButtonText');

    ... .addClass("active"); 

});

So result should be:

html:

<li>...<li> 
<li class="active">
    <a class="myCheckboxLink" tabindex="0">
        <span class="myCheckboxSpan">
            <i class="fa fa-check fa-check-checkbox" aria-hidden="true"></i>
        </span>
        <label class="radio">
            <input value="" type="radio">Name
        </label>
    </a>
</li>
<li>...<li> 

Fiddle: https://jsfiddle.net/ewm9pbqv/

2 Answers 2

1

You can use .filter() with .addClass() in this case:

$('li').filter(function() { 
   return $(this).find('input:radio').val() == ""; 
}).addClass('active');
Sign up to request clarification or add additional context in comments.

1 Comment

Unfortunately it does not seem to work. Please check it out: jsfiddle.net/ewm9pbqv
1

Try this

$('li input[value=""]').closest("li").addClass('active');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.