Hey friends,
Do check out my YouTube channel to watch this tutorial and subscribe to support me. Thanks!
<!-- Created by CodingPorium,2021. Visit https://youtube.com/c/CodingPorium for more tutorials with free source code -->
<!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>Read More Read Less Button using JS | CodingPorium</title>
</head>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
*{
padding:0;
margin:0;
box-sizing:border-box;
}
::selection{
background-color:#0c9496;
color:white;
}
body{
background-color:#0c9496;
color:black;
display:flex;
justify-content:center;
align-items:center;
height:100vh;
font-family:poppins;
font-size:20px;
}
.container{
width:90%;
max-width:500px;
margin:0 auto;
background-color:white;
border-radius:8px;
padding:1rem;
display:flex;
flex-direction:column;
}
button{
margin-top:40px;
width:fit-content;
padding:5px;
font-size:20px;
font-family:poppins;
background-color:#0c9496;
color:white;
border:none;
border-radius:5px;
cursor:pointer;
align-self:flex-end;
transition:0.3s;
outline:none;
}
button:hover{
opacity:0.7;
}
#more{
display:none;
}
</style>
<body>
<div class="container">
<p>
Lorem Ipsum is simply dummy text of the printing and
typesetting industry. Lorem Ipsum has been the industry's
standard dummy text ever since the 1500s,
<span id="dots">...</span>
<span id="more">
when an unknown printer took a galley of type and scrambled it to make a
type specimen book. It has survived not only five centuries, but also the
leap into electronic typesetting, remaining essentially unchanged.
</span>
</p>
<button onclick="Function()" id="myBtn">Read More</button>
</div>
</body>
<script>
function Function(){
var dots = document.getElementById("dots");
var moreText = document.getElementById("more");
var btnText = document.getElementById("myBtn");
if(dots.style.display === "none"){
dots.style.display = "inline";
btnText.innerHTML = "Read More";
moreText.style.display = "none";
}else{
dots.style.display="none";
btnText.innerHTML = "Read Less"
moreText.style.display = "inline";
}
}
</script>
</html>
Post a Comment