Change contents in a modal

I wish to anticipate that I am just an amatorial developer, therefore some of my queries may sound silly to most of you.
I would like, if possible to change the content (text) in a modal when clicking outside buttons, without repeating the coding for the modal.
E.g. : I have “btn1”, “btn2”, “btn3”. If I press btn1 the modal opens displaying a textA, if press btn2 displays txtB, etc.
Would it be possible with HTML and CSS only (maybe JS as I already used it in my original code)? Thank you in advance. Valter

no, HTML and CSS only no, they allow only for static code

You need to use JavaScript, but it also depends on the code you already have

//Get modal element
var modal = document.getElementById(‘simpleModal’);
//Get open modal button
var modalBtn = document.getElementById(‘modalBtn’);
//Get close button
var closeBtn = document.getElementsByClassName(‘closeBtn’)[0];

//Listen for open click
modalBtn.addEventListener(‘click’, openModal);

//Listen for close click
closeBtn.addEventListener(‘click’, closeModal);

//Listen for outside click
window.addEventListener(‘click’, clickOutside);

//function to open modal
function openModal() { = ‘block’;

//function to close modal
function closeModal() { = ‘none’;

//function to close modal outside
function clickOutside(e){
if ( == modal){ = ‘none’;

this is the JS code, it applies to one button only (modalBtn);
I have thought using the condition if - then
like if id=modalBtn then


; if id=modalBtn2 then


; etc.
But I am not really good in coding with JS.
Thanks anyway for the info…

can you give a codepen, or at least eniugh code to reproduce the thing?

you can create the modal with parametric content

like, you have a function that is called with a different argument based on what button is clicked, the function activates the modal and the argument determines what the modal content is

meaning, changing the JS code?

Yes, that would be pretty much all JavaScript

ok, noted, thank you very much for your advice. Then I will have to seek the help of somebody more professional and expert than me. I know little about JS… :pray: