I am trying to use the add function to add an HTML fragment to a div but I can't get it to work. My code:
$('#curveContainer').add('<img src="http://upload.wikimedia.org/wikiped开发者_开发问答ia/commons/f/f0/Blue-dot-5px.png" alt="test" />');
Fiddle here - http://jsfiddle.net/7a86g/4/
You want append()
, not add()
.
From the add()
documentation...
Given a jQuery object that represents a set of DOM elements, the .add() method constructs a new jQuery object from the union of those elements and the ones passed into the method.
append()
will add the new content to the DOM
Fiddle here - http://jsfiddle.net/7a86g/5/
You can also use html()
to completely replace the contents of the matched element.
精彩评论