jQuery animate width on button text change -
if have button default css, how can make when click button, text changes , it's width animated fit in new text?
html
<button>click me</button>
jquery
$(document).on("click", "button", function(){ $(this).text("you have clicked me!", function(){ $(this).animate({width:"auto"}, 1000); }); })
jsfiddle
you cannot animate width/height auto,
instead give invisible similar element width/height auto , saves calculated value, animate own element calculated value.
here link explain how it.
Comments
Post a Comment