1

Possible Duplicate:
Class name change Event in jQuery

I am using jquery along side bxsilder.

I need jquery to recognise a class change on a link which will then animate an image along a line.

On page load div1 .pager-active moves the image along the line to left: 15% When next is pressed the link under div2 gets the class .pager-active and so on.

So I need jquery to recognise that div2 now has the class .pager-active there for animating the img to left:50%

Below is the code I have been working with which works on initial load for div1 but doesn't detect any class changes after load.

if( $('#div1 .pager-active').length){
    $('.line img').animate({'left' : '15%'},600);
        };

if( $('#div2 .pager-active').length){
    $('.line img').animate({'left' : '50%'},600);
        };

if( $('#div3 .pager-active').length){
    $('.line img').animate({'left' : '85%'},600);
        };

Any help would be great.

Community
  • 1
  • 1

3 Answers3

0

You can get the class change event as posted here :

Class name change Event in jQuery

but you may try this solution too :

When next is pressed, get id of div having class .pager-active . Use getAttr() for this. Once you have the id, remove it's class, attach class to next div in line and perform the effect.

Community
  • 1
  • 1
Akshat Goel
  • 538
  • 4
  • 18
  • thanks for the link, I have tried the link and it had some effect but how could I make it unique for each of the 3 divs? currently I can only get it working when I add $('.line img').animate({'left' : '5%'},600); – user1415102 May 24 '12 at 14:25
0
var oldClass = $("#div").attr('class');
if(oldClass != $("#div").attr('class');
{
 //Do something?
}

Something like that maybe?

Hawiak
  • 553
  • 1
  • 9
  • 32
0

try DOMAttrModified event:

document.getElementsById('div2').addEventListener('DOMAttrModified', function(e){
  if (e.attrName === 'style') {
    ...
  }
}, false);
Ram
  • 143,282
  • 16
  • 168
  • 197