<!DOCTYPE html>
<
html
lang
=
"en"
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"IE=edge"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
title
>Geeksforgeeks</
title
>
<
style
>
.container {
text-align: center;
}
.text-div {
margin: 50px auto;
width: 80%;
}
label {
display: block;
margin-bottom: 10px;
}
input[type="text"] {
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
width: 100%;
box-sizing: border-box;
font-size: 16px;
margin-bottom: 10px;
}
button {
padding: 10px 10px 10px 10px;
margin-bottom: 1rem;
background: green;
color: white;
border: none;
border-radius: 6px;
cursor: pointer;
transition: all linear 0.5s;
}
button:hover {
transform: translate(0px, -6px);
}
</
style
>
</
head
>
<
body
>
<
div
class
=
"container"
>
<
h1
>Underline Text Example</
h1
>
<
div
class
=
"text-div"
>
<
label
for
=
"takeInput"
>Enter text to underline:</
label
>
<
input
type
=
"text"
id
=
"takeInput"
>
<
button
onclick
=
"underlineText()"
>Click to underline</
button
>
<
div
id
=
"output"
></
div
>
</
div
>
</
div
>
<
script
>
function underlineText() {
// Get the user input
const takeInput = document.getElementById("takeInput").value;
// Get the output element
const output = document.getElementById("output");
// Check if user input is empty
if (takeInput === "") {
output.innerHTML = "Please enter some text to underline.";
return;
}
// Create a new string with the underlined text
const underlinedText = "<
u
>" + takeInput + "</
u
>";
// Set the innerHTML of the output element to the underlined text
output.innerHTML = underlinedText;
}
</
script
>
</
body
>
</
html
>