I’m trying to line break the text for INDIVIDUAL and PHONE. I figured out how to break the text, but I can’t get it to line up with the other text.
Current code
document.getElementById("department").innerHTML = department[i]
document.getElementById("location").innerHTML = locationA[i]
document.getElementById("people").innerHTML = peopleCurrentVarStr.replace(/,/g, "<br>")
document.getElementById("phone").innerHTML = phoneNumberStr.replace(/,/g, "<br />")
span.a {
width: 100px;
height: 100px;
background-color: yellow;
}
<h1>DEPARTMENT: <span class="a" id="department"></span></h1>
<h1>LOCATION: <span class="a" id="location"></span></h1>
<h1>INDIVIDUAL: <span class="a" id="people"></span></h1>
<h1>PHONE: <span class="a" id="phone"></span></h1>
3
Answers
for your innerHTML you should probably output them into lists
<ul><li></li></ul>
First, you should avoid using
innerHTML
when possible due to security and performance implications. And, when the text you are working with doesn’t contain any HTML, you definitely shouldn’t use.innerHTML
and instead just use.textContent
. Then, within your JavaScript strings, you can use the escape code for a new line:n
.Also, your use of
h1
is incorrect. Heading elements (h1...h6
) should be used to set up document structure, not because of the way they style text. As such, there should rarely be more than oneh1
on a page.Finally, to your question, if you simply place each piece of data into its own
span
element and, with CSS, set thosespan
s to beinline-block
, you can then set a width for the two columns of data contained within your elements and you’ll be all set:The way your code is being presented, it looks more like a definition list and a bunch of headlines.