<header>
<h1>Working with the DOM - substring comparisons</h1>
</header>
<main>
<h2>Text to be tested</h2>
<p id="start">
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Quis, officiis!
</p>
<h3>Results of substring test</h3>
<p id="result"> </p>
</main>
html,
body {
width: 75%;
font-family: "Cochin", serif;
margin: 1rem auto;
color: darkgreen;
}
header {
background-color: lightgrey;
text-align: center;
padding: 4px;
border-radius: 10px;
text-decoration: underline;
text-underline-offset: 10px;
box-shadow: 2px 0 12px grey;
border: 1px inset lightgrey;
}
main {
margin: 12px auto;
background-color: lightgrey;
padding: 4px;
border-radius: 20px;
box-shadow: 0 2px 12px grey;
border: 1px inset lightgrey;
}
h2 {
text-align: center;
}
p {
font-size: 16px;
padding: 0 10px;
}
#start {
text-align: center;
}
#result {
font-size: 20px;
padding: 10px 40px;
margin: 10px 40px;
border: 1px dotted green;
}
#debugr {
font-size: 20px;
font-style: bold;
margin: 40px;
padding: 10px;
border: 1px dotted green;
}
hr {
margin-top: 2rem;
border: none;
border-top: 1px dotted green;
}
h3 {
text-align: center;
}
@media screen and (max-width: 480px) {
body {
width: 100%;
}
}
let startText = document.getElementById("start");
let resultText = document.getElementById("result");
let debugrText = document.getElementById("debugr");
let substringText = startText.textContent.substring(0, 5);
if (startText.textContent.includes("Lorem")) {
resultText.innerText = "Well this is awkward ...";
} else {
resultText.innerText = "All seems to be well ...";
}
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.