locked
Jquey Filter RRS feed

  • Question

  • User-155787703 posted

    How to make null or not null base select field uisng jquery Query Filter ...

    Monday, November 14, 2016 4:05 PM

Answers

  • User-691209617 posted

    Please see below mentioned example and you can use it according to your implementation.

    $('select option')
        .filter(function() {
            return !this.value || $.trim(this.value).length == 0;
        })
       .remove();
    
    $('select option')
        .first()
        .prop('selected', true);​
    • you can use .filter() to filter out the empty option elements and remove them all at once

    • use .prop() to set special attributes like selected

    jQuery("#sender_container input.required").filter(function() {
        return !this.value;
    }).addClass("error");​

    Also read below mention documentation.

    https://api.jquery.com/has-attribute-selector/

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, November 14, 2016 4:11 PM