<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="utf-8">
<style>
#text {
width:300px;
height:100px;
overflow:hidden;
border:1px solid #bbb;
padding:5px;
}
#text>div {
font-family:Arial;
line-height:1.5em;
color:Grey;
}
#text:before {
content:"+";
float:right;
border:1px solid #808080;
width:20px;
height:20px;
text-align:center;
cursor:pointer;
}
.less>div {
color:black!important;
}
.less:before {
content:"-"!important;
}
</style>
</head>
<body>
<div id='text'>
<div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>
</div>
</body>
</html>
<script>
// Generamos el evento click en el id "text"
document.getElementById("text").addEventListener('click',function(e){
// comprovamos que se haya pulsado sobre el cuadro creado con #text:before
// Los valores varian dependiendo del padding que tiene #text y el tamaño que
// tiene #text:before
if(e.clientX>=this.offsetWidth-20 && e.clientX<=this.offsetWidth+1 &&
e.clientY<=this.offsetTop+27 && e.clientY>=this.offsetTop+6) {
// Comprovamos si esta la clase less en el div #text
if(this.classList.contains("less"))
{
// Añadimos la clase "less" para cambiar el signo del boton
this.classList.remove("less");
this.style.height="100px";
}else{
// Quitamos la clase "less"
this.classList.add("less");
this.style.height="inherit";
}
}
});
</script>
Comentarios sobre la versión: Versión 1.0 (2)