MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

jQuery Syntax!

The jQuery syntax is tailor-made for selecting HTML elements and performing some action on the element(s).

Basic syntax is: $(selector).action()

  • A $ sign to define/access jQuery
  • A (selector) to “query (or find)” HTML elements
  • A jQuery action() to be performed on the element(s)

Examples:

$(this).hide() – hides the current element.

$("p").hide() – hides all <p> elements.

$(".test").hide() – hides all elements with class=”test”.

$("#test").hide() – hides the element with id=”test”.

<script type="text/javascript">

$(document).ready(function(){

// your code

$(selector).action();

});

</script>Code language: HTML, XML (xml)

If you observe above jQuery syntax, we placed a jQuery code inside of </script> tag because jQuery is a just JavaScript library.

Following is a detailed explanation of the above jQuery syntax.

$ – The dollar sign ($) is just an alias name of jQuery and it is used to define or access the jQuery.

$(document).ready(function(){}) – It represents the document ready event and it is used to execute the jQuery code once the document is fully loaded and ready before working with it.

In above jQuery syntax, we written a $(selector).action() jQuery statement in document ready event to select and perform required actions such as setting the content or changing the color, etc. on HTML elements.

selector – It represents the HTML element of which manipulation needs to be done.

action() – It represents an action that needs to be performed on the given element.

The jQuery team provided a shorter way for document ready event (document.ready) with an anonymous function ($(function(){})).

By using document ready event shorter way, the above jQuery syntax can be rewritten as shown following.

<script type="text/javascript">

$(function(){

// your code

$("#selector").action();

});

</script>Code language: HTML, XML (xml)

Now we will see the simple example of using jQuery to set the div element text after the DOM is ready, for that write the code like as shown below.

If you observe above example, we defined a document ready event with jQuery statement to find all the div (Here div is a jQuery selector) elements in the page and set the content to “Welcome to DevopsSchool” using text() action method.

Suppose if we want to replace the div text, once the user performs some action, then we need to write the code as shown below.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services — all in one place.

Explore Hospitals

Related Posts

What is Jquery and use cases of Jquery?

What is Jquery? Jquery is a fast and concise JavaScript library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. It…

Read More

What is Jquery and How it works? An Overview and Its Use Cases

What is jQuery? jQuery is a fast and concise JavaScript Library created by John Resig in 2006 with a nice motto: Write less, do more. jQuery simplifies HTML…

Read More

Top 50 interview questions for JQuery

The JQuery is a wild, minor, and feature-rich JavaScript library. It brands things like HTML document traversal and operation, event handling, animation, and Ajax much humbler with…

Read More

Laravel – select dropdowns that filter results in a table ‘on change’

Hello, I am working on an application that is kind of an eCommerce application that have a table of product and I want to add a filter…

Read More

DataTables images issues like sort_asc.png & sort_both.png not found

Hi Friends, I am facing these issues for the last 1 month so I decided to solve this issue then I tried and I succeed. this is…

Read More

How to Use Dropdown Search Functionality with Pagination in Laravel PHP Framework?

Step 1. Firstly, add dropdown in blade file according to below code,here mention name=”city_filter” and id id=”city_filter” step 2:pass id in table tag in step 3: write…

Read More