tags:

views:

46

answers:

1

hello.

i have this :

<script>var newnumber="680";</script> <div id="number-area">458<div> <button onclick="changeit()">

i want a jquery code to change the content of the div "number-area" to the variable "newnumber".

and that's with a fad in & fad out like when you click "digg" button on digg website.

Thanks

+5  A: 
  function changeit() {
    $('#number-area').fadeOut('slow', function() {
      $('#number-area').html(newnumber).fadeIn('slow');
    });
  }

You will probably need to change #number-area to a node traversal. Also you're not ending you're div after 458, I'm guessing you meant </div> at that point.

Edit: You can see how digg did their by putting javascript:alert(dig) into your address bar. They used the animate in combination with opacity by the looks of it. Not sure why they did that instead of the fadeOut and in methods.

Edit1: Shortened thanks to Doug.

Yuriy Faktorovich
Thanks yuriy :)
David
@Yuriy. Your answer could be substantially shortened by chaining and using `this` : `$('#number-area').fadeOut('slow', function(){ $(this).html(newnumber).fadeIn('slow'); });` (But +1 for a great answer :)
Doug Neiner