Solution 1 :

Might be untidy but would work.

using an escape character

onclick="MapPopUp('Example','hi nr how are you doing')"

and your MapPopUp function can look something like this.

   function MapPopUp(header, content) {
      PopUpDiv.classList.remove('hidden');
      PopUpHeader.innerHTML = header;
      let contentHtml = '';
      content.split('nr').forEach(c => {
        contentHtml += `<p>${c.trim()}</p>`;
      });
      PopUpContent.innerHTML = contentHtml;
    }

Solution 2 :

Try this.

    div= document.getElementById("popUp");
    br = document.createElement("br");
    div.appendChild(br);

Problem :

I’m trying to write out a p in my onclick=(”,”) with linebreaks, but br wont work.

I want to be able to do this:

‘hi
how are you doing?’

Html:

<area shape="circle" coords="200,38,28" onclick="MapPopUp('Example','hi how are you doing')" alt="">

<div id="popUp" class="hidden">
            <h3 id="popUpHeader"></h3>
            <p id="popUpContent"></p>
            <div>
                <a onclick="CloseMapPopUp();">
                    <img id="close" src="images/close.png" alt="close button">
                </a>
            </div>
        </div>

JS:

function MapPopUp(header, content) {
    PopUpDiv.classList.remove("hidden");
    PopUpHeader.innerHTML = header;
    PopUpContent.innerHTML = content;
}

function CloseMapPopUp() {
    PopUpDiv.classList.add("hidden");
    PopUpHeader.innerHTML = "";
    PopUpContent.innerHTML = "";
}

var PopUpDiv = document.getElementById("popUp");
var PopUpHeader = document.getElementById("popUpHeader");
var PopUpContent = document.getElementById("popUpContent");

I hope someone out there can help
In advance thanks for your help!!!

Comments

Comment posted by Arturas Lapinskas

innerHtml creates just a text string with ‘
‘ inside?

Comment posted by Arturas Lapinskas

You should add a dom element, instead of a string, i think

Comment posted by Arturas Lapinskas

You can also try n or nr instead of the

By