jQuery Add To Div Examples

  Buffer

While working with jQuery, it may be desirable at times to add new data or info to a div. This is true especially when working with databases or with dynamic data. So in this article, I am going to share with you how to use jQuery to add to div. You can add another element or html or text. Read on to find out more.

How to use jQuery to add to div

So let’s see how we can do that by means of examples. Consider that we have a div with the ID “my_div”. I would now like to add a different element to this div. I would like to add a paragraph to div when a button is clicked. Also to illustrate that the paragraph is being added, I am adding red background color to the paragraph.

When the button is clicked, note that the background color of the div. What internally happens is that instead of just directly adding the paragraph to the div (as you would normally expect), jQuery merely adds the styling associated with it and not the “p” tag itself.

Example: Add content, HTML tags, etc. to div using jQuery

Conclusion:

Using .add() method to an element simply adds the properties of the new element to the existing element without adding the new element itself.

Your Turn!

Do you know of any other ways to use jQuery to add to div? Feel free to suggest by commenting below.

a You May Also Like

m Never Miss A Post

We will send you FREE periodical updates whenever we publish a new article so that you can remain on top of technology. We will NEVER send unsolicited email. That’s our GUARANTEE !!!

The above article has the following Categories and Tags applied to it:
B Categories: jQuery, Tips and Tricks
About the Author

f About Author:

Founder of Extreme Web Designs and currently works as Web Designer, Web Developer, Blogger and as an Editor. He is the brains behind the Extreme Web Designs Labs, a one-stop growing resource for Free Web Design & Web Development tools that help increase productivity and cut down on web design & development time. Connect with Rocky Dev on G+ and follow him on Twitter.

Y U No Comment? Say Something Useful!

*


Refresh Code

*

*

Get more traffic, increase your profits with our services
Get FREE Website Design and Web Development Quote!
Visit Extreme Web Design's Labs for more Free tools!