Estou tentando de várias formas a dias mas não tenho conseguido fazer este script pegar o valor do <h3>
e retornar o texto para ele truncado.
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>
A ideia é trazer o conteúdo da notícia que está no banco de dados através do repeater, e depois fazer com que o JavaScript pegue o valor e trunque o texto.