Video tutorial illustrating the syntax of Descendant selectors.
For the purpose of demonstration, we are using simple html structure. It may not suit the requirement of a descendant selector, but we’re using it to keep things simple and easy to understand the syntax of descendant selectors.
In a complex xHTML or XML structure we could have multiple p tags nested inside a div tag and you want one of these p tags to work on. In such a complex case, you are better to go with descendant selectors.
You could select it as follows:
1
$("div p:first")
$("div p:first")
Here it selects the first p tag present inside the div.
jQuery uses simple verbs like first, append, remove etc: which we’ll cover in upcoming tutorials.
Video tutorial illustrating simple tweaks which help optimize / improve the performance of jQuery Applications.
To Optimize 1. Write all javascript programs in an external file and embed it into the html pages. 2. Whenever possible, embed the javascript file at the end of body tag. i.e., just before the closing body tag. 3. It’s also good practice to separate CSS coding to an external file and then embed it to the web pages.
How it helps ? 1. i. If you have thousands of web pages, writing the same code on all the pages and maintaining it and/or modifying it is a touch job. Having it in an external file helps in re-usability and maintainability. ii. It only loads the javascript files once and do not load the same files again and again for all other pages, hence saving a lot of bandwidth. Also highly optimizing the load time of web pages. 2. When the parser encounters these javascript files, they stop loading all other elements and allocate all its bandwidth to load javascript file. So writing it at the end of body tag helps. Since all other important elements like images, content will be loaded before these time-consuming javascript files.
Video Tutorial: Optimize / Improve Performance of jQuery Applications
Above video uses Animation of Text and Image: jQuery code to illustrate the optimization concept. If you have not already seen the video, we highly encourage you to watch it and practice it.
In our future tutorials we will be writing most of our javascript code in external file and will be embedding them at the end of body tag. With this tutorial you know why we would do that!
Video tutorial to illustrate animation of text and image using jQuery.
In this tutorial, we accomplish: Animation of text: using animate method. Display of hidden image: using fadeIn method. Toggle of image: using slideToggle method. Change the color of the text being animated: using jQuery’s css method.
Here we have 4 buttons, 1 div tag which contains some string in it, and 1 image tag. Each button has its own unique ID, which is referenced to track user click event.
Once the #top button is clicked, the string inside div tag(which has move as its id), moves upwards leaving 30px from top of the document and 200px from left.
Once the #down button is clicked, the string inside div tag(which has move as its id), moves down leaving 200px from top of the document and 200px from left.
Once the #blue button is clicked, the color of string inside div tag(which has move as its id), changes to blue. .css() method takes 2 parameters, first one being css property and the second one its value.
Once the document is ready and the user clicks on the button(with togg as its id), the image fades In and fades Out. This fadeIn and fadeOut effect is accomplished using fadeToggle method of jQuery.
To understand the basic coding of jQuery, please watch previous day videos about selectors and methods.
Inside the HTML document we have added a image and a button. Once the user clicks on this button, our jQuery code gets executed and the fade In and fade Out effect is presented to the user. For the jQuery code to be interpreted by the javascript interpreter, we need to include the jQuery standard library file to our web page.
Some basic CSS makes the image look well positioned.
Practice this image effect program and also try using .fadeIn(); .fadeOut();
.slideIn(); .slideOut(); .slideToggle();
functions instead of .fadeToggle(); function.
Also notice that, page doesn’t reload while you perform these DOM manipulations using jQuery. This is a major advantage which builds up rich user experience.
This video tutorial shows the basics of jQuery Selectors, Methods and some nice little image and text effects.
It’ll be fun..
Note: $(); is a shortcut to $jQuery(); and it’s called Selector. Its used to select id’s, class, elements.
Selecting id’s, classes and elements is similar to that of CSS Selectors. For id use # symbol. For Class use . symbol. For tags or elements, use tag name or element name.
We’ll come up with some more video tutorial ..stay subscribed, and try these fun program yourselves too.
Also share how you’re using jQuery in your projects and what you actually want to accomplish using it.
Sign into our forum and start discussing various jQuery and other topics and share your ideas and learn more collectively.
If you were not able to execute the above program, then need not worry, just search on our blog and you’ll find full detailed video tutorial writing and executing it step-by-step. Hope you’re enjoying it.