Search code examples
jqueryimagehtmlpopulate

jquery to populate div with image and populate input


I have the following jquery syntax that populates an input in my table row with a value:

row.find('input[name^="bandstatus"]').val('InRange');

In each row, I have a unique div named priceflag in which I want to show a green flag image or red flag. so 1st row is priceflag1, 2nd row is priceflag2, 3rd row is priceflag3 etc...

normally I would populate a div with $('#results').html(data); but how do I populate the corresponding table row div with an image.

something like:

$('name^="priceflag).val(\images\redflag.png)

Hope this question makes sense.

Thanks a million as always.


Solution

  • $('[name^="priceflag"]').html('<img src="/images/redflag.png" />')
    

    Note you have to be aware of using back slashes like you are doing. In javascript, the sequence "\r" is actually a carriage return when it appears inside a string. All modern operating systems recognize forward slashes in paths.