How to create a new img tag with JQuery, with the src and id from a JavaScript object?

后端 未结 4 1085
眼角桃花
眼角桃花 2020-12-02 14:01

I understand JQuery in the basic sense but am definitely new to it, and suspect this is very easy.

I\'ve got my image src and id in a JSON response (converted to an

4条回答
  •  死守一世寂寞
    2020-12-02 14:49

    In jQuery, a new element can be created by passing a HTML string to the constructor, as shown below:

    var img = $(''); //Equivalent: $(document.createElement('img'))
    img.attr('src', responseObject.imgurl);
    img.appendTo('#imagediv');
    

提交回复
热议问题