Dave's Brain

Browse - programming tips - jquery inject insert html

Date: 2009dec13
Language: javaScript

Q.  How do I insert/inject html into a page with jQuery?

A.  Use before() or after() like this:

	$('#my_id').before('<b>Hello</b>');
	$('#my_id').after('<b>Hello</b>');

There are also insertBefore() and insertAfter() methods but
they work in a way I found counter-intuitive.

The wrap() method is useful in some cases.

If you want to replace the HTML in a tag use html() like this:

	$('#my_id').html('<b>Hello</b>');

More info:
http://docs.jquery.com/Manipulation
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2010, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.