2
I have a div
that has news, I need to hide a part of the text when the file is read by the browser, in addition the user can see the full text if he wants to click on "See More" which is a tag <a>
and then reduce it. I came to this:
<script type="text/javascript">
//quando a pagina for carregada o texto da notícia será reduzido a 100 letras apenas.
$(document).ready(function(){
txt = document.getElementById('texto-principal-noticia').innerHTML;
var txt2 = txt.substr(0,100);
var complemento = '...';
txt3 = txt2 + complemento;
document.getElementById('texto-principal-noticia').innerHTML = txt3;
});
function Mostrar(){
if(txt<txt3){
document.getElementById('texto-principal-noticia').innerHTML = txt;
document.getElementById('link-noticia').innerHTML = 'Mostrar Menos';
}else{
document.getElementById('texto-principal-noticia').innerHTML = txt3;
document.getElementById('link-noticia').innerHTML = 'Mostrar Mais';
}
}
With this you can hide the text and open it when the function mostrar
is called, but when the function is called again to this time hide the text it does not work, someone knows tell me why?
I think the problem is in the probation check, but when I change the operators it still doesn’t work.
It would be better to use Ellipsis in overflow, and just change the div’s style, wouldn’t it? You can do this with pure CSS, no JS, following functional demonstration here: https://answall.com/a/110958/70
– Bacco