jQuery Syntax


The jQuery statement usually begins with a dollar sign ($) and ends with a semicolon (;).

The jQuery syntax focuses on selecting HTML elements and performing some actions on the elements.

A $ sign to define as jQuery.

A (selector) to “query (or find)” HTML elements.

A jQuery action() to be performed on the elements.

Syntax

<script type="text/javascript">
$(document).ready(function(){
   $(selector).action();
});
</script>

Example

<!DOCTYPE html>
<html>
<head>
  <title>jQuery syntax example</title>
  <script src="jquery.min.js"></script>
  <script>
    $(document).ready(function() {
      var data = $("p").html();
      console.log(data);
    });
  </script>
</head>
<body>
  <p>This is paragraph tag.</p>
</body>
</html>