JQuery: Is it possible to test both input type and attribute in one selector?

I have a list of elements inputand with a single selector I want to find those that

  • - flags
  • have an attribute value

Can I do it?

I tried:

  • $(items).find("input:checkbox[value]")
  • $(items).find("input[value]:checkbox")

But both ignore [value]and verify only input:checkbox.

Of course, I can use two selectors, but only one will be nicer.


My main use case for this .

Basically, I want to do some actions on a flag depending on whether or not other flags are unchecked. In this example, the parent flag is still checked, because the jQuery selector "input[value]:checkbox"in the function getChildrenCheckboxesmatches the No child flag, as well as other flags.

+3
2

-, , , .

-, filter(), , :

$('input[value!=""]:checkbox').addClass('selected');

http://jsfiddle.net/niklasvh/pEK3c/

$('input:checkbox').filter(function(){
 return this.value.length;   
}).addClass('selected');

example: http://jsfiddle.net/niklasvh/duAB8/

, $('input[value]') value, -, , , , -, , , , , ?

:

<input type="checkbox" value="2" />
<input type="checkbox" value="" />
<input type="checkbox"  />
<input type="checkbox" value="23" title="a" />

:

$('input:[value]:checkbox').prop('checked',true);

:

Chrome 11, X - - X
FF4,       X - X X
IE 8,      X - X X

, , , ? , . X - - X.

, [title]...

+4

EDIT:

, value, : http://api.jquery.com/multiple-attribute-selector/

$("input[type='checkbox'][value]")
0

All Articles