$ Each and Templates


In this lesson we learn about jQuery each method and also some details about templates. First we are going to set up a template with use of each method.

Let see a first look of the Template

Image

Result

Image

In above example first we create a non Java script tag block and give it to an id is blogTemplate and after than we set value h2 and images for title and thumbnail. Than we create a self invoking function and inside it create a var content and set their object property inside arrays block or braces. Here we use a new method $ trim which use for remove all spaces from code and than we use $ each method. By default we have to pass there 3 values inside each method that are 1. content which we use, 2. call back function and 3. pass arguments. Let try this code your self and see the results.

Let replace title with object

Image

Result

Image

Final code for template design

Image Image View Demo

Wconcert India © 2015   ·   All Rights Reserved

Free Web Hosting