Jquery Syntax
jQuery Syntax
With jQuery you lot conduct (query) HTML elements in addition to perform "actions" on them.
jQuery Syntax
The jQuery syntax is tailor-made for selecting HTML elements in addition to performing about 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 travel performed on the element(s)
$(this).hide() - hides the electrical flow element.
$("p").hide() - hides all <p> elements.
$(".test").hide() - hides all elements amongst class="test".
$("#test").hide() - hides the chemical component subdivision amongst id="test".
Are you lot familiar amongst CSS selectors?
jQuery uses CSS syntax to conduct elements. You volition acquire to a greater extent than nearly the selector syntax inward the side past times side chapter of this tutorial.
jQuery uses CSS syntax to conduct elements. You volition acquire to a greater extent than nearly the selector syntax inward the side past times side chapter of this tutorial.
The Document Ready Event
You mightiness accept noticed that all jQuery methods inward our examples, are within a document laid event: $(document).ready(function(){
// jQuery methods become here...
});
This is to forbid whatsoever jQuery code from running earlier the document is finished loading (is ready).It is proficient practise to await for the document to travel fully loaded in addition to laid earlier working amongst it. This too allows you lot to accept your JavaScript code earlier the torso of your document, inward the caput section.
Here are about examples of actions that tin neglect if methods are run earlier the document is fully loaded:
- Trying to enshroud an chemical component subdivision that is non created yet
- Trying to acquire the size of an picture that is non loaded yet
$(function(){
// jQuery methods become here...
});
Use the syntax you lot prefer. We mean value that the document laid effect is easier to sympathise when reading the code.
Comments
Post a Comment