Reputation: 221
please i need help in appending image src into select option in javascript
here is my code :
$.ajax({
type: "POST",
url: "http://10.102.220.119:8001/api/1/device/devices",
dataType: "json",
data: { ids : ids},
success:function(data){
for (var i = 0 ; i<data.length;i++){
var image = data[i].image;
var mime = data[i].mime;
var img = new Image();
img.src = "data:"+mime+";base64,"+image;
document.body.appendChild(img);
/*var option = document.createElement("option");
option.data-img-src = img.src;
var select = document.getElementById("selectImage");
select.appendChild(option);*/
}
}
});
i use
option.data-img-src = img.src;
but it display this error :
Invalid left-hand side in assignment
please any help
Upvotes: 2
Views: 825
Reputation: 18873
Try (pure javascript):
option.setAttribute('data-img-src', img.src);
Upvotes: 1
Reputation: 9963
When the key of an object contains -
you can use option["data-img-src"]
instead
Upvotes: 1