jquery find first code example

Example 1: jquery remove class

//Remove this same line after copying
Basic Syntax:
$(element).removeClass( "myClass yourClass" )
-------------------------------------------------------------------------------------
  
Html code example:
<p class="red highlight">test1</p>
<p class="red highlight marked">test2</p>
<p class="red highlight">test3</p>
<p class="red highlight">test4</p>

// remove all highlight class from p tag
<script>
	$( "p" ).removeClass( "highlight" )
</script>

// output after execution of this code
<p class="red">test1</p>
<p class="red marked">test2</p>
<p class="red">test3</p>
<p class="red">test4</p>

Example 2: select the first elemnt have class in jquery

$( ".box" ).first().css( "font-style", "bold" );

Example 3: jquery first child

$('div:first-child')

Example 4: select the first elemnt have class in jquery

<script>
  // jquery
$( "tr:first" ).css( "font-style", "bold" );
</script>

Example 5: how to select the first div in jQuery

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>first demo</title>
  <style>
  td {
    color: blue;
    font-weight: bold;
  }
  </style>
  <script src="https://code.jquery.com/jquery-3.5.0.js"></script>
</head>
<body>
 
<table>
  <tr><td>Row 1</td></tr>
  <tr><td>Row 2</td></tr>
  <tr><td>Row 3</td></tr>
</table>
 
<script>
$( "tr:third" ).css( "font-style", "italic" );
</script>
 
</body>
</html>