Spec-Zone.ru › jQuery

:checkbox Селектор

селектор checkbox

Описание: Выбирает все элементы типа checkbox.

  • версия добавлена: 1.0jQuery( ":checkbox" )

$( ":checkbox" ) эквивалентно $( "[type=checkbox]" ). Как и другие псевдоклассовые селекторы (те, которые начинаются с ":"), рекомендуется предварять его именем тега или каким-либо другим селектором; в противном случае подразумевается универсальный селектор ("*"). Другими словами, чистый $(':checkbox') эквивалентен $( "*:checkbox" ), поэтому $( "input:checkbox" ) следует использовать вместо него.

Дополнительные замечания:

  • Поскольку :checkbox является расширением jQuery и не входит в спецификацию CSS, запросы, использующие :checkbox , не могут воспользоваться приростом производительности, предоставляемым методом native DOM querySelectorAll() . Для лучшей производительности в современных браузерах используйте [type="checkbox"] вместо этого.

Пример:

Находит все входные элементы типа checkbox.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>checkbox demo</title>
  <style>
  textarea {
    height: 25px;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.7.0.js"></script>
</head>
<body>
 
<form>
  <input type="button" value="Input Button">
  <input type="checkbox">
 
  <input type="checkbox">
  <input type="file">
  <input type="hidden">
 
  <input type="image">
  <input type="password">
  <input type="radio">
 
  <input type="reset">
  <input type="submit">
  <input type="text">
 
  <select>
    <option>Option</option>
  </select>
 
  <textarea></textarea>
  <button>Button</button>
</form>
 
<div></div>
 
<script>
var input = $( "form input:checkbox" )
  .wrap( "<span></span>" )
  .parent()
  .css({
    background: "yellow",
    border: "3px red solid"
  });
 
$( "div" )
  .text( "For this type jQuery found " + input.length + "." )
  .css( "color", "red" );
 
// Prevent the form from submitting
$( "form" ).on( "submit", function( event ) {
    event.preventDefault();
} );
</script>
 
</body>
</html>

Демо:

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/checkbox-selector

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API