Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide character in jquery

Tags:

jquery

I need hide character after 35 and when I hover text show full text help me

<a class="dep_buttons" href="#"> something text something text something text something text something text something text </a>

$('.dep_buttons').mouseover(function () { 
    if($(this).text().length > 30) {
       $(this).stop().animate({height:"150px"},150);
}
})
$(".dep_buttons").mouseout(function(){
    $(this).stop().animate({height:"40px"},150);
});
like image 634
Val Do Avatar asked Jan 29 '14 07:01

Val Do


People also ask

How to show hide using jQuery?

Syntax: $(selector). hide(speed,callback);

How to div hide in jQuery?

Using jQuery The most common approach to hide an element in jQuery is to use the . hide() method. It works by setting the display CSS property to none . Now the document is rendered as though the element did not exist.

How does jQuery hide work?

hide() is fired immediately and will override the animation queue if no duration or a duration of 0 is specified. As of jQuery 1.4. 3, an optional string naming an easing function may be used. Easing functions specify the speed at which the animation progresses at different points within the animation.

Which jQuery method is used to hide selected element?

The hide() is an inbuilt method in jQuery used to hide the selected element. Syntax: $(selector).


3 Answers

Demo FIDDLE

Jquery

    $(function () {
    $('.dep_buttons').each(function () {
            var stringText = $(this).text().trim();
            var substringText=stringText.substring(stringText,35);
            var remainingText=stringText.substr(35);
        $(this).html(substringText);
         $('.dep_buttons').mouseover(function () { 
                $(this).find('a').show();
          }).mouseout(function(){
                $(this).find('a').hide();
            });

        $('<a style="display:none;">'+remainingText+'                 </a>').appendTo($(this));
        });
});
like image 183
P.Sethuraman Avatar answered Sep 29 '22 18:09

P.Sethuraman


Do this like that :

var text = $('.dep_buttons').text();
if(text.length > 35) {
    var subText = text.substring(0,35) + '...';
    $('.dep_buttons').text(subText);
    $('.dep_buttons').mouseover(function () { 
        $('.dep_buttons').text(text);    
    });
    $(".dep_buttons").mouseout(function(){
        $('.dep_buttons').text(subText);
    });
}

Fiddle

like image 43
guli Avatar answered Sep 29 '22 17:09

guli


Here is Demo

I used slice method of Javascript.

$(function(){
   var text = $('.dep_buttons').text();         
    var rem = text.slice(29, $('.dep_buttons').text().length);
text = text.replace(rem,"");
    var span = text + " <span class='toggleText'>"+rem+"</span>"            
$('.dep_buttons').text("").append(span);    
    $('.dep_buttons').mouseenter(function () {             
      $(this).find(".toggleText").stop().animate({opacity:1},500);
   });
   $(".dep_buttons").mouseleave(function(){             
      $(this).find(".toggleText").stop().animate({opacity:0},500);
    });
})
like image 20
Pramod Avatar answered Sep 29 '22 19:09

Pramod