settingsAccountsettings
Menusettings

Q: Show More Task in HTML with DOM and JavaScript

+2 votes

Write a JS function that expands a hidden section of text when a link is clicked. The link should disappear as the rest of the text shows up.

Input/Output:
There will be no input/output, your program should instead modify the DOM of the given HTML document.

Sample HTML:

Welcome to the "Show More Text Example".
<a href="#" id="more" onclick= "showText()">Read more …</a>
<span id="text" style= "display:none">Welcome to JavaScript and DOM.</span>
<script>
  function showText() {
    // TODO
  }
</script>

Examples:

show more task with javascript

asked in JavaScript category by user andrew

1 Answer

+1 vote

Here is the solution:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
Welcome to the "Show More Text Example"
<a href="#" id="more" onclick="showText()">Click HERE to Read More...</a>
<span id="text" style="display: none">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Architecto autem commodi corporis debitis eaque eos, exercitationem explicabo harum maiores maxime minima molestiae mollitia nam nisi obcaecati perferendis possimus quam quod?</span>

<script>
    function showText() {
        document.getElementById("text").style.display = "inline";
//        document.querySelector("#text").style.display = "inline";
        document.getElementsById("more").style.display = "none";
    }
</script>
</body>
</html>

 

answered by user eiorgert
...