开发者

Why doesn't this jQuery add an image to my div?

开发者 https://www.devze.com 2023-04-12 18:17 出处:网络
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:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消