The following code will:
- Test to see if the characters in a
divare more then ten chars long - Shorten the text to less than ten characters
- Append
...to thediv - On hover, it will show and hide a
divthat is intended to show the full text
I edited this once I found one of the problems
so far it works with only the first div and no others
<html>
<head>
<title>limit chars 1</title>
<script type="text/javascript" language="javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#div2").hide();
var elem = $("#div1");
var fn1 = function(){ $('#div2').show();};
var fn2 = function(){ $('#div2').hide();};
if(elem){
if (elem.text().length > 10)
elem.text(elem.text().substr(0,12)
)}
if(elem){
if (elem.text().length > 10)
elem.text(elem.append("...")
)};
if(elem){
if (elem.text().length > 10)
//elem.text(elem.append("...")
$(elem).mouseover(fn1).mouseout(fn2);
};
//$(elem).mouseover(fn1).mouseout(fn2);
});//end
</script>
<style>
#div2{color:blue; }
</style>
</head>
<body>
this is where the fun begins.
<div id="div1">
12345ebfkqbweub qiuweiu
</div>
<div id="div2">full text in tooltip</div>
</body>
</html>
Try assigning your event handlers in your
if (elem.text().length > 10)block.To work on multiple
divs, you would want to use thejQuery.eachfunction: http://api.jquery.com/each/