简体   繁体   中英

Jquery select all selected and checked elements at once

What I need is, find all selected elements on a page (I can do this by using $(":selected") ) and find all checked elements on a page (I can do this by using $(":checked") ).

Is there any way to find all selected and checked elements by using only one jQuery statement/selector?

Have you tried the following?:

$(":selected, :checked")

Here an example of how you can do it:

if ($( ":checked, :selected"))
{
  $( "#message" ).html( "BOTH Select box and Checkbox are choosen!" );
};

JSFiddle

Yes, use can use

$(':checked, :selected')

This will select all the checked and selected elements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM