• jQuery-Add Elements

    jQuery-Add Elements

    In jQuery, there is easy to add elements and its contents. jQuery has four methods that is used to add new elements or contents.

    1. append() – Inserts content at the end of the selected elements
    2. prepend() – Inserts content at the beginning of the selected elements
    3. after() – Inserts content after the selected elements
    4. before() – inserts content before the selected elements

    Add several new elements with append() and prepend() methods.

    Both the append() and prepend() methods can take an infinite number of new elements as parameters. The new elements can be generated with text/HTML, with jQuery, or with JavaScript code and DOM elements.

    In the following example, we create several new elements. The elements are created with text/HTML, jQuery, and JavaScript/DOM. Then we append the new elements to the text with the append() method.

    Example of append()/prepend() methods

    Add several new elements with after() and before() methods.

    Both the after() and before() methods can take an infinite number of new elements as parameters. The new elements can be generated with text/HTML, with jQuery, or with JavaScript and DOM elements.

    In the following example, we create several new elements. The elements are created with text/HTML, jQuery and JavaScript/DOM. Then we insert the new elements to the text with the after() method.

    Example of after()/before() methods

    Appreciate my work :Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrDigg thisShare on YummlyShare on VKFlattr the authorBuffer this page

Leave a Reply

Your email address will not be published. Required fields are marked *