Home    Articles

 

Introduction to jQuery

 

You need to know

jQuery makes easy to:

Here he have some simple HTML:

<!DOCTYPE html>
<html>
<head>
  <title>Introduction to jQuery</title>
</head>
<body>
  <h1>This is a header!</h1>
  <p>This is a paragraph.</p>
</body>

To select and return an element (h1 in this case) we simply write:

$("h1")

Below we can see how we change a text within a h1 node element:

$("h1").text("This is the new header")

Because jQuery may execute before the web page is loaded, we need to be sure our scripts are triggered after the page is loaded. So we need to be listening for an signal that tells us the webpage is ready to execute some scripts. To do that, we tell our function to wait for the page to be loaded, and only after that to run the code:

jQuery(document).ready(function(){
  $("h1").text("This is the new header");
});

 

by