jQuery multiple selector

jQuery multiple choice mode:

$("selector1,selector2,selectorN");

Each of the selector returns the matching element combined together, any number of selectors can be specified, and the combined matching element into one result.

Sample code:

<!DOCTYPE html>
<html>
<head lang="zh-CN">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
    <title>多项选择器</title>
    <style></style>
</head>

<body>
    <div id="one" class="number">1</div>
    <div id="two" class="string">2glass</div>
    <div id="three" class="string">3monkey</div>
    <div id="four" class="number">4</div>
    <script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
    <script type="text/javascript">
     $(document).ready(function() {
      //此处填写代码
      var a=$('#one,.string,div');
      console.log(a);

    });
    </script>
</body>

</html>

Console print the results:

id selector "#one" and clas Selector ".string" containing the element selected in the selector element "div", but the number of selector jQuery end result is a collection of all elements in the order html document stream arrangement.

After manually try selector code change the order, the order of the final elements of the collection has changed?

var a=$('.string,#one,div');
console.log(a);

 

Guess you like

Origin www.cnblogs.com/f6056/p/11002958.html