Horje
How to select multiple elements using jQuery ?

In this article, we will learn how to select multiple elements using JQuery. JQuery is the fastest and most lightweight JavaScript library that is used to simplify the interactions between an HTML/CSS document, or more precisely the Document Object Model (DOM), and JavaScript. JQuery is widely famous for its motto of “Write less, do more.” It simply means that you can achieve your goal by just writing a few lines of code.

Approach: We can select as many classes as we want using ‘$’ to select classes. If you wish you can specify any number of selectors to combine into a single result. This multiple-expression combinator is an efficient way to select dissimilar elements and the order of the DOM elements in the returned jQuery object may not be identical, as they will be in document order.

Syntax:

$( "classOne, classTwo, classThree" )
      .css( "property name", "value" );

Example: In this example, we are using the above-explained approach.

HTML

<!doctype html>
<html lang="en">
<head>
    <style>
        div,
        span,
        p {
            width: 126px;
            height: 60px;
            float: left;
            padding: 3px;
            margin: 2px;
            background-color: #eee;
            font-size: 14px;
        }
 
        body {
            text-align: center;
        }
    </style>
    <script src=
    </script>
</head>
 
<body>
    <h1 style="color:green">
        GeeksForGeeks
    </h1>
    <div>Linux</div>
    <p class="myClass">
        Windows
    </p>
 
    <p class="notMyClass">
        Pizza
    </p>
 
    <span>MacOS</span>
    <script>
        $("div, span, p.myClass")
            .css("border", "5px solid green");
    </script>
</body>
</html>

Output:




Reffered: https://www.geeksforgeeks.org


JQuery

Related
jQWidgets jqxTreeMap colorRange Property jQWidgets jqxTreeMap colorRange Property
jQWidgets jqxGrid cellselect Event jQWidgets jqxGrid cellselect Event
jQWidgets jqxTreeMap colorRanges Property jQWidgets jqxTreeMap colorRanges Property
jQWidgets jqxChart showSerie() Method jQWidgets jqxChart showSerie() Method
jQWidgets jqxChart saveAsPNG() Method jQWidgets jqxChart saveAsPNG() Method

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
11