0

I found this script (more/less text). When I implemented to code with jQuery lib 1.11, he does not work. I can not know why?

Code:

<span class="teaser">text goes here</span>
<span class="complete"> this is the complete text being shown</span>
<span class="more">more...</span>

jQuery:

$(".more").toggle(function(){
  $(this).text("less..").siblings(".complete").show();    
}, function(){
  $(this).text("more..").siblings(".complete").hide();    
});

Can ask for help? Thanks

ondra15
  • 143
  • 4
  • 16
  • 1
    Are there any errors in your browser's JavaScript console? What does "not work?" Mean, specifically? Oh, and [`toggle()`](http://api.jquery.com/toggle-event/) was removed in jQuery 1.9; so there *should* be errors. – David Thomas Sep 29 '14 at 11:52
  • see http://stackoverflow.com/a/14383246/128165 for an implementation of the deprecated `toggle` method. – Gabriele Petrioli Sep 29 '14 at 12:14

1 Answers1

2

toggle is used on the elements you want to show and hide, rather than being an event that happens. You probably want to bind to the click event of more:

$(".more").click(function(){
  if ($(this).siblings(".complete").is(":visible"))
      $(this).text("more..").siblings(".complete").hide();    
  else
      $(this).text("less..").siblings(".complete").show();    
});

The toggle event was deprecated in jQuery 1.8 and removed in 1.9.

Updated fiddle

James Thorpe
  • 31,411
  • 5
  • 72
  • 93