hello world jquery

Hello world jquery

If you're a web developer, you must have heard about the jQuery library. It's a popular JavaScript library that simplifies HTML document traversing, event handling, animating, and AJAX interactions for rapid web development.

What is "Hello World" in jQuery?

"Hello World" in jQuery is a simple program that displays "Hello World" on the web page using jQuery. Here is how you can write the "Hello World" program in jQuery:


      $(document).ready(function() {
        $("body").append("Hello World");
      });
    

The above code adds an h1 heading with the text "Hello World" inside the body element of the web page. The $() function is used to select HTML elements, and the .append() method is used to add new content to the selected elements. The code is wrapped inside the $(document).ready() method to ensure that it runs only when the document is fully loaded.

Another way to write "Hello World" in jQuery:

Here is another way to write the "Hello World" program in jQuery:


      $(function() {
        $("

This code also adds an h1 heading with the text "Hello World" inside the body element of the web page. The $() function is a shorthand notation for $(document).ready(), and the .text() method is used to set the text content of the new element. The .appendTo() method is used to append the new element to the selected elements.

So, these are the two ways to write "Hello World" in jQuery. You can choose any of these methods, depending on your preference and coding style.

Subscribe to The Poor Coder | Algorithm Solutions

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]
Subscribe