I have a div
that has a 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 you want by clicking "View More" which is a <a>
and then make it reduced. 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 hide the text this time it does not work, can someone tell me why?
I think the problem is in the conditional check, but when I change the operators it still does not work.