Caius Eugene
Caius Eugene

Reputation: 855

jQuery fade content within a div

Hey there, so far i have this, it toggles my footer down and up, but i want the content of the footer to fade out and new content fade in when it's toggled down. I can't for the life of me work it out, please help! - thanks

$(document).ready(function() {
  $('#footertab').toggle(function() {
    $('#footer').animate({
      bottom: '-=120'
    }, 1000);
  },function() {
    $('#footer').animate({
      bottom: '+=120'
    }, 1000);
  })
});

Upvotes: 3

Views: 5583

Answers (2)

electblake
electblake

Reputation: 2176

You may want to look into the 2nd parameter of the jQuery selector - "Selector Context", which is a great shorthand for searching for elements within a context.

The following would add a class of 'bar' to the span contained within a clicked div:

$('div.foo').click(function() {
  $('span', this).addClass('bar');
});

(from api documentation)

Internally, selector context is implemented with the .find() method, so $('span', this) is equivalent to $(this).find('span').

Further Reading..

Upvotes: 1

robbrit
robbrit

Reputation: 17960

Use the children() function:

$("#footer").children().fadeOut();

Upvotes: 3

Related Questions