Home > Article > Web Front-end > Introducing the use of wildcards in jQuery selectors
This article mainly introduces the wildcard in the selector of jQuery. Friends who need it can refer to
1. Selector
(1 ) Wildcard:
Copy code The code is as follows:
$("input[id^='code']");//id All input tags whose attributes start with code
$("input[id$='code']");//All input tags whose id attribute ends with code
$("input [id*='code']"); //All input tags whose id attribute contains code
(2) Select ## based on index
#Copy code The code is as follows:
$("tbody tr:even"); //Select all tr tags with even numbers
$(" tbody tr:odd"); //Select all tr tags with odd indexes
(3) Get the number of inputs of the next-level node of jqueryObj
Copy code The code is as follows:
jqueryObj.children("input").length;
(4) Obtain class as All tags under the child nodes of the main tag
Copy code The code is as follows:
$(".main > a ");
(5)Select the label immediately adjacent
Copy code The code is as follows:
jqueryObj.next("p");//Get the p immediately behind the jqueryObj tag, nextAll gets all
2. Filter
Copy code The code is as follows:
//not
$("#code input:not([id^='code'])");//id is The code tag does not contain all input tags whose id starts with code
The code is as follows:
//Process keyboard operations on the text boxjqueryObj.keyup(function(event){
var keyCode = event.which;//Get the current pressed The key value of the keyboard, the Enter key is 13
}
The code is as follows:
$('#someField').val($.trim($('#someField').val()));//Eliminate spaces, syntax: $.trim(value)The above is the detailed content of Introducing the use of wildcards in jQuery selectors. For more information, please follow other related articles on the PHP Chinese website!