Hitesh Chauhan Hitesh Chauhan - 1 year ago 114
HTML Question

how to add src of image using jquery append function?

add src of image using jquery append function. i am using a variable in foreach loop and i wants to append image src . how do i do that.

my jquery code

$.each(data.products, function(key,val) {
$("div#yourwishlist").append('<div class="col-sm-6 col-md-4"><article class="box"><figure><a class="hover-effect" title="" href="#"><img width="300" height="160" alt="" src="'+val('thumb')+'"></a></figure><div class="details"><a class="pull-right button uppercase" href="" title="View all">select</a><h4 class="box-title">'+val['name']+'</h4><label class="price-wrapper"><span class="price-per-unit">$170</span>avg/night</label></div></article></div>');

this code is not working in my case ...

Answer Source

Hitesh you can add src attribute to an image like:

$.each(data.products, function(key,val) {
   $("div#yourwishlist").append('<img width="300" height="160" alt="" src="'+ val +'">');

// here val contains the path of image in it
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download