How to load image from a JS

0

Inside my div 'data' I load the JS information by the id inside the spans, I am not able to load the image inside the span id = 'imgspan'

    <div class="dados">
       <label><span id="orderid"></span></label>
        <label><span id="endereco"></span></label>
        <label><span id="bairro"></span></label>
        <label>imagem: <span id="imgspan" /></label>
    </div>

$('#cities').change(function() {
      var orderid = values[$(this).val()].OrderID;    
      var endereco = values[$(this).val()].Endereco;
      var bairro = values[$(this).val()].Bairro;
      var imgspan= values[$(this).val()].ImgSpan;

      $('#orderid').text(orderid);
      $('#endereco').text(endereco);
      $('#bairro').text(bairro);
      $('#imgspan').text(imgspan)
    });

MY JS

 var values = [
             {"OrderID": "Santo André",
              "Endereco": "Rua Bernardino de Campos, 171",
              "Bairro":"Centro",
              "ImgSpan":"<img src='../img/pointer.png' alt='' />"
              }]
    
asked by anonymous 21.03.2016 / 13:54

2 answers

0

Try the following:

          var values = [
         {"OrderID": "Santo André",
          "Endereco": "Rua Bernardino de Campos, 171",
          "Bairro":"Centro",
          }
         function image() {  
         var img = document.createElement("imgspan"<img src="../img/pointer.png">;  
         img.src = "../img/pointer.png"";  
         document.getElementById('imgspan').appendChild(img);  
         }]

And the code:

      <div class="dados">
      <label><span id="orderid"></span></label>
      <label><span id="endereco"></span></label>
    <label><span id="bairro"></span></label>
    <label>imagem: <div id="imgspan"></div></label>
</div>

   $('#cities').change(function() {
  var orderid = values[$(this).val()].OrderID;    
  var endereco = values[$(this).val()].Endereco;
  var bairro = values[$(this).val()].Bairro;
  var imgspan= values[$(this).val()].ImgSpan;

  $('#orderid').text(orderid);
  $('#endereco').text(endereco);
  $('#bairro').text(bairro);
  $('#imgspan').text(imgspan)
});
    
21.03.2016 / 17:57
0

I was able to resolve using:

<div class="dados">
       <label><span id="orderid"></span></label>
        <label><span id="endereco"></span></label>
        <label><span id="bairro"></span></label>
        <label>imagem: <span id="imgspan"></span> </label>
    </div>

$('#cities').change(function() {
      var orderid = values[$(this).val()].OrderID;    
      var endereco = values[$(this).val()].Endereco;
      var bairro = values[$(this).val()].Bairro;
      var imgspan= values[$(this).val()].ImgSpan;

      $('#orderid').text(orderid);
      $('#endereco').text(endereco);
      $('#bairro').text(bairro);
      $( '#imgspan' ).empty();
      $('#imgspan').append(imgspan);

    });

and in JS

 var values = [
             {"OrderID": "Santo André",
              "Endereco": "Rua Bernardino de Campos, 171",
              "Bairro":"Centro",
              "ImgSpan":"<img src='../img/pointer.png' alt='' />"
              }]
    
21.03.2016 / 20:36