I have a function to show/hide text and it works fine. I have two issues, however:
Here is the Javascript function (it could be better, I know)
function showHide(mytext) {
if (document.getElementById('mytext1')) {
if (document.getElementById('mytext1' + '-show').style.display != 'none') {
document.getElementById('mytext1' + '-show').style.display = 'none';
document.getElementById('mytext1').style.display = 'inline';
document.getElementById('mytext1').style.textAlign ='justify';
} else {
document.getElementById('mytext1' + '-show').style.display = 'inline';
document.getElementById('mytext1').style.display = 'none';
}
}
}
Here is some HTML
<p class="NeueLite text-justify"> Beginning of the text.<a id="mytext1-show" onclick="showHide('mytext1'); return false;" class ="abstract"> More</a>
<div id="mytext1" style="display: none;" class="moretext">
Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.Hidden/shown text.
<a id="mytext1-hide" onclick="showHide('mytext1');return false;" href="javascript:void(0)" class="abstract" >Less</a></p></div>
And the classes of my CSS :
div.moretext {
font-family: 'Comic Neue', sans-serif !important;
font-weight: 100 !important;
line-height: 1.2 !important;
font-size: 0.8rem !important;
text-align: justify !important;
}
This is because you put the hidden text in a <div>
. Use a <span>
instead. Also, put the text-align: justify;
in the <p>
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.