How to load img into jquery

1

Hello everyone, I would like to know how to load image into an append ();

follow the link

append("<tr><td>"+value.codigo+"</td><td>"+value.nome+"</td><td>CARREGAR IMAGEM AQui</td><tr>");
    
asked by anonymous 17.12.2015 / 20:19

2 answers

1

Just put inside the src of an img:

var linkImagem = 'http://lorempixel.com/image_output/abstract-q-g-640-480-4.jpg';
$("body").append(" <img src=" + linkImagem + " alt='Exemplo'> ");
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.1/jquery.min.js"></script>
    
17.12.2015 / 20:35
1

To create an element and insert it with jQuery you can do this:

jQuery('<img />', {
    src: "img/edit.png"
}).appendTo(td);

You can also add this code in string, I do not like it but if you want it could be something like:

var table = ...
var img = '<img src="img/edit.png" class="btn-action">';
[value.codigo, value.codigo, null].forEach(function(thing, i, arr){
    var tr = document.createElement('tr');
    var td = document.createElement('td');
    td.innerHTML = i == (arr.length - 1) ? img : thing;
    tr.appendChild(td);
    table.appendChild(tr);
});
    
17.12.2015 / 23:46