Jake query syntax is specifically made for selecting each GMO elements and performing some type of action
on an individual element or group of elements.
The basic syntax looks as follows.
A dollar sign is to define an access J query a selector is to query or find specific each GMO elements
a J query action is to be performed on the elements it's also a good practice to nest.
J query methods and functions inside a document ready event that looks like this.
This prevents any J query code from running before the document is finished loading will come back to
this point in a moment.
Let's take a look at an example to better illustrate this concept.
We'll create a script that allows users to hide any text contained within a paragraph tag in an each
terminal document by clicking a button Here's a demonstration of what the script will do.
Here we have two lines of text and also a heading the two lines of text are contained within paragraph
tags.
When we click the high text button those two text lines disappear.
And that's what the script will do.
Let's go ahead and get started on the script.
First we need to create a few blocks of text in our body type type the following in with it in between
your open and closed body tags
we'll start with the header.
Now we have our two paragraphs created.
And lastly we need to create our button
next we'll create our script starting with the document ready function
this section here is the hide function that will be triggered when the button is clicked.
Remember that we've specified that only the text in the paragraph tags should be hidden when the button
is clicked.
So the event is specified here the action.
Hi and the element is P which is for the paragraph elements
and this will all be triggered when the button is clicked
and that's it.
The function should now work we'll go ahead and save the file and preview it in our web browser.
And so you can test that out in yours as well.