I'm trying in a number of ways to days but I have not been able to get this script to get the value of <h3>
and return the text to it truncated.
JavaScript:
<script type="text/javascript">
function truncar() {
var texto = document.getElementById("texto_noticia");
var limite = 350;
if (texto.length > limite) {
limite--;
last = texto.substr(limite - 1, 1);
while (last != ' ' && limite > 0) {
limite--;
last = texto.substr(limite - 1, 1);
}
last = texto.substr(limite - 2, 1);
if (last == ',' || last == ';' || last == ':') {
texto = texto.substr(0, limite - 2) + ' [...]';
} else if (last == '.' || last == '?' || last == '!') {
texto = texto.substr(0, limite - 1);
} else {
texto = texto.substr(0, limite - 1) + ' [...]';
}
}
alert(texto);
return (texto);
}
</script>
HTML:
<h3 id="texto_noticia" class="texto_noticia">
<%# Eval("Noticia_Conteudo")%>
</h3>
The idea is to bring news content that is in the database through repeater , and then have JavaScript take the value and truncate the text.