jQuery: Change html of element added with append()
Using jQuery, how can I add text to an element I add using append?
Can this be done with one line?
In the example below, the text is NOT added to the paragraph that is created with append()
<html><head><title>Hello</title><script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script><script type="text/javascript">$(document).ready(function() { $('div').append('<p />').html('This text should in inside the p with a red background');});</script><style type="text/css">div {margin: 50px auto;padding: 30px;border: 1px solid #000;background: #aaaaff;width: 500px;}p {width: 200px;background: #ffaaaa;margin: 50px auto;padding: 30px;border: 1px solid red;}</style></head><body><div></div></body></html>
Open in new window
Example : http://sdparkes.co.uk/ee_ex/jquery_append.php