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?