By using our mini forum, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy

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.

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>
  function showText() {
    // TODO


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">
    <meta charset="UTF-8">
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>

    function showText() {
        document.getElementById("text").style.display = "inline";
//        document.querySelector("#text").style.display = "inline";
        document.getElementsById("more").style.display = "none";


answered by user eiorgert