The following script works well to both truncate a link and add an icon class BUT, It was too slow: using document.ready to hold the code from executing UNTIL all the elements on a page loaded.
I removed it, AND it works BUT it won't work on the last element
<script>
jQuery.noConflict();
jQuery(".resultAction").each(function(){
var fileName = jQuery(this).find('a').html()
var fileExtension = fileName.substring(fileName.lastIndexOf('.') );
var nameChars= fileName.length;
var shorter=fileName.substring(0,10)+"...";
//apply style to relative to file extension
if(fileExtension=="jpg"||"pdf"||"mov"){
jQuery(this).find("#indicator").addClass("is" + fileExtension.slice(1) );
}
//no file extension hide the icon div "indicator"
if((fileExtension.indexOf('.') == -1)){
jQuery(this).find("#indicator").addClass("not");
}
//truncate text
if(nameChars>10){
jQuery(this).find('a').text(shorter);
}
});
</script>
so I got rid of the .ready above and added this over again:
<script>
jQuery(document).ready(function(){
jQuery.noConflict();
jQuery(".resultAction:last").each(function(){
//-SAME CODE ABOVE-....
</script>
-notice the :last -which of course works -but it's redundant and I was wondering if there is a more efficient way to both make this code run instantly (as the page loads each element) and completely instead of running two identical scripts one to run fast, and one to apply to the last item it missed.