Expand my Community achievements bar.

Join us for the Community Q&A Coffee Break on May 2nd at 8 am PT with Adobe Journey Optimizer experts Robert Calangiu, Brent Kostak & Sandra Hausmann.
SOLVED

Image as dynamic content in compatibility mode

Avatar

Level 2

How can I put an image as dynamic content if I import an HTML and i am in compatibility mode.

I don't see the option to create dynamic content

Cannot use structure, content, and fragment components

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

@sebastian_quevedo ,

If you're working with HTML in compatibility mode and cannot use structure, content, and fragment components, you can still add dynamic content to your page using JavaScript.

One way to add an image dynamically is to create an IMG element in JavaScript and append it to the DOM.

Something like this -

var img = document.createElement("img");
img.src="path/to/image.jpg";
// Append the image element to a container in the DOM
var container = document.getElementById("image-container");
container.appendChild(img);

Through this, you create a new "image" element and set its src attribute to the image path you want to display.
Then you find a container element in the DOM (using getElementById or some other method) and append the image element to it.

View solution in original post

1 Reply

Avatar

Correct answer by
Employee Advisor

@sebastian_quevedo ,

If you're working with HTML in compatibility mode and cannot use structure, content, and fragment components, you can still add dynamic content to your page using JavaScript.

One way to add an image dynamically is to create an IMG element in JavaScript and append it to the DOM.

Something like this -

var img = document.createElement("img");
img.src="path/to/image.jpg";
// Append the image element to a container in the DOM
var container = document.getElementById("image-container");
container.appendChild(img);

Through this, you create a new "image" element and set its src attribute to the image path you want to display.
Then you find a container element in the DOM (using getElementById or some other method) and append the image element to it.