Harry Forbess
Harry Forbess

Reputation: 2134

changing and image in a div but can't give it and javascript variable id

I thought this would be simple. I am changing an image in div but I can't seem to set the id of the image of the div.

    var my_html = "<img src=\"/img/lock.png\" id=\"" + json_obj.ITEM_VALUE_ID "+  \" />"
     $("#up-down-icons-"+id+"-"+level).html( my_html  );

I get

    <img id=" + json_obj.ITEM_VALUE_ID + " src="/img/lock.png">

json_obj.ITEM_VALUE_ITEM is defined. Can anyone see what I am doing wrong? I think I just need a second pair of eyes. thanks

Upvotes: 0

Views: 40

Answers (2)

codingbiz
codingbiz

Reputation: 26386

It should be this

var my_html = "<img src=\"/img/lock.png\" id=\"" + json_obj.ITEM_VALUE_ID +  "\" />"

You just misplaced the position of the plus

Upvotes: 1

MyBoon
MyBoon

Reputation: 1298

You have an error in your javascript syntax, This is a good way :

var my_html = "<img src='/img/lock.png' id='" + json_obj.ITEM_VALUE_ID + "' />";
$("#up-down-icons-"+id+"-"+level).html(my_html);

Upvotes: 1

Related Questions