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);
});
Syntax: $(selector). hide(speed,callback);
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.
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.
The hide() is an inbuilt method in jQuery used to hide the selected element. Syntax: $(selector).
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));
});
});
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
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);
});
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With