Using jQuery

jQuery is an extremely powerful JavaScript library. Here are a few sample pieces of code to give you a head start on your next project.

If you have downloaded the jQuery library to your hard disk and plan to use it from there, then you can include the following code in your HTML <head> tag:

<script src="js/jquery.min.js"></script> 

Here, js is a folder in the root directory of your project.

Tip

To avoid longer loading time and performance issues, scripts should be added to the end of the <body> tag because when the browser loads the web page (let's say, sample1.html) and the scripts are at the end of the body tag, the browser can render the content of the page (the body) and only start loading scripts afterward.

Another preferred approach is to use the Google hosted libraries; these provide faster rendering to your pages and jQuery code than using your own hosted jQuery libraries. You can use the Google developer hosted libraries with the following piece of code:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
</script>

The jQuery syntax is used to perform any specific action on elements of HTML.

The basic syntax is as follows:

$(selector).action()

Here is the description:

  • $: $ is used to access the jQuery object.
  • (selector): The query (or find) HTML elements using familiar CSS-style selector syntax. For example, you can select by element name, type, class or id.
  • jQuery action(): For example, it can be events like click, keypress, focus and so on.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.216.47.169