0

I am a newbie when it comes to javascript as I am more custom to vba for office.

However, now I want to write several paragraphs at the same page, but only showing the first, say to or three sentences of each paragraf and add a link in the text; see more...

By clicking the link, see more..., it should show the whole paragraph and the link see more... should change to see less... at the end of the paragraf.

I would like to have a javascript function to do this, taking an argument, perhaps an ID of the html.element to show or hide. That way I could reuse code or function, for each paragraph.

Any suggestions or samples would be very appriciated.

So if I have three paragraph at the same page, it should be able to display and hide part of the paragraph for each paragraph independently of each other.

I found this code but it is hard coded:

<button onclick="myFunction()">Click Me</button>

<script>
function myFunction() {
  var x = document.getElementById("myDIV");
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>

However, I want to reuse the function for any paragraph I want to. So I tried to make in a function with argument, but it does not seem to work?

    <button onclick="myFunction("myDIV")">Click Me</button>

<script>
function myFunction(EliD) {
  var x = document.getElementById(EliD);
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
</script>

Anybody that have a suggestion how to do this?

JanGT
  • 1
  • 1
  • Please do your own [research](https://stackoverflow.com/search) - So many answers and tutorial on `google` on *Simple hide and show text with javascript* – Always Helping Aug 11 '20 at 07:52
  • [Simple hide and show text with javascript](https://www.google.com/search?q=hide+and+show+text+with+javascript&rlz=1C1CHZL_enAU805AU805&oq=hide+and+show+text+with+javascript&aqs=chrome..69i57.303j0j1&sourceid=chrome&ie=UTF-8) – Always Helping Aug 11 '20 at 07:53
  • check this https://stackoverflow.com/a/28742816/4592066 – Rahul Sawant Aug 11 '20 at 10:08

0 Answers0