Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a Values into a div created from document.createElement

I have a DIV that is created from document.createElement,, I have a few text and a image that needs to be added to this DIV. Could some one suggest me the best way to do it? The image path is given in the image variable. Below is the code that i have already written. contentattachpoint is another DIV that is there in the HTML page which is got by

var contentattachpoint=document.querySelector('.contentattachPoint');


var year="Year of Manufacture:"+arr[i].year;
var power="Engine Power:"+arr[i].power;
var description="Description:"+arr[i].description;
var image=arr[i].image;
var details = document.createElement("div");
details.setAttribute("id", "details");
details.className = "details";
details.value=year+power+description;
contentattachpoint.appendChild(details)

Thanks in advance.

like image 987
Some Guy Really Avatar asked Feb 19 '26 09:02

Some Guy Really


1 Answers

By what I understand of you question I consider that you need text and image both in the div that you created so do something like this

details.innerHTML = description + "<img src='"+image+"'>";
like image 61
chandresh_cool Avatar answered Feb 20 '26 22:02

chandresh_cool



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!