How to use querySelectorAll only for elements that have a specific attribute set?

后端 未结 3 416
深忆病人
深忆病人 2020-12-22 20:57

I\'m trying to use document.querySelectorAll for all checkboxes that have the value attribute set.

There are other checkboxes on the page t

3条回答
  •  春和景丽
    2020-12-22 21:33

    You can use querySelectorAll() like this:

    var test = document.querySelectorAll('input[value][type="checkbox"]:not([value=""])');
    

    This translates to:

    get all inputs with the attribute "value" and has the attribute "value" that is not blank.

    In this demo, it disables the checkbox with a non-blank value.

提交回复
热议问题