-->

jQuery element Selector

By: Bipin C Mathew 9 months, 1 week ago

The Element Selector Selects all elements with the given tag name. In the Element Selector we can list the names of the element to be selected in the parenthesis. For example $("h2") will select all h2 element of the HTML page, similarly $("p") will select all the paragraph elements of the page.  We can use the element selector to select an element whose name is passed in the parenthesis inside $().


Syntax  $("element")

Example

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>element demo</title>
<style>
   div, span {
         width: 60px;
         height: 60px;
         float: left;
         padding: 10px;
         margin: 10px;
         background-color: #eee;
   }
</style>
<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
</head>
<body>

<div>DIV1</div>
<div>DIV2</div>
<span>SPAN</span>

<script>
      $( "div" ).css( "border", "9px solid red" );
      $( "span" ).css( "border", "9px solid green" );

</script>

</body>
</html>

Comments

Let us talk!

We take the vision which comes from dreams and apply the magic of science and mathematics, adding the heritage of our profession and our knowledge to create a design.