Saturday, August 20, 2022

More button and cards with JavaScript

<!DOCTYPE html>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<style>

#more {display: none;} // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

</style>

</head>

<body>

<h2>Read More Read Less Button</h2>

<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim ligula venenatis dolor.</span></p>

<button onclick="myFunction()" id="myBtn">Read more</button>

<script>

function myFunction() {

  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>

</body>

</html>


https://webdesign.tutsplus.com/tutorials/how-to-implement-a-load-more-button-with-vanilla-javascript--cms-42080

https://www.w3schools.com/howto/howto_css_button_on_image.asp

https://www.knowledgehut.com/blog/web-development/react-card-ui-component

https://css-tricks.com/a-complete-guide-to-links-and-buttons/

https://javascript.info/event-delegation

https://dmitripavlutin.com/javascript-event-delegation/

No comments:

Post a Comment