jQuery Example

jQuery is developed by Google. To create the first jQuery example, you need to use JavaScript file for jQuery. You can download the jQuery file from jquery.com or use the absolute URL of jQuery file.

In this jQuery example, we are using the absolute URL of jQuery file. The jQuery example is written inside the script tag.

Let's see a simple example of jQuery.

File: firstjquery.html
Test it Now

Output:

The first paragraph is selected.

The second paragraph is selected.

The third paragraph is selected.

$(document).ready() and $()

The code inserted between $(document).ready() is executed only once when page is ready for JavaScript code to execute.

In place of $(document).ready(), you can use shorthand notation $() only.

The above code is equivalent to this code.

Let's see the full example of jQuery using shorthand notation $().

File: shortjquery.html
Test it Now

Output:

The first paragraph is selected.

The second paragraph is selected.

The third paragraph is selected.


function() { $("p").css("background-color", "cyan"); }

It changes the background-color of all

tag or paragraph to cyan.

Next TopicjQuery Selectors




Contact US

Email:[email protected]

jQuery Example
10/30