Toggle slider with external files (live issue?)
Hi guys,
I'm trying to create a really basic accordion/slider as a header for my site. There are two different banners, the big one (banner_a), and a small version (banner_b). banner_a initially starts open, and banner_b hidden. When a user clicks the .toggle button, I want banner_a to slide close, and then banner_b to slide open and vice versa. I have got this working okay.
My problem comes as each banner has quite a lot of content, so I want to to use two external files banner_a.php and banner_b.php - banner_a.php is loaded initially, and then I try and use ajax() to alternately load the files.
The first time I press the .toggle button it works exactly as I want it to - banner_a closes, banner_b opens. The second time banner_b closes - banner_a doesn't appear. Then third time banner_b appears again - and so on with banner_b opening and closing.
What am I doing wrong? I have a feeling it have something to do with live()? I had a long play and couldn't work it out (I really don't know much about javascript/jquery). Any help would be really appreciated! Thanks.
- // Toggle banner
- $('.toggle').click(function() {
-
- $(this).find('a').toggleClass('active');
-
- if ($(this).find('a').is('.active')) { // If banner_a is open
-
- $('#banner_a').slideToggle('slow'); // Slide banner_a closed
-
- $.ajax({
- url: 'banner_b.php',
- success: function(data){
- $('#container').empty(); // Remove banner_a
- $('#container').html(data); // Load banner_b
- $('#banner_b').hide(); // Hide banner_b
- $('#banner_b').slideToggle('slow'); // Slide banner_b open
- }});
-
- } else { // If banner_b is open
-
- $('#banner_b').slideToggle('slow'); // Slide banner_b closed
-
- $.ajax({
- url: 'banner_a.php',
- success: function(data){
- $('#container').empty(); // Remove banner_b
- $('#container').html(data); // Load banner_a
- $('#banner_a').hide(); // Hide banner_a
- $('#banner_a').slideToggle('slow'); // Slide banner_a open
- }});
-
- }
- });