views:

31

answers:

3

Further to my last question I need to add in the .live() function as i'm adding the content dynamically

This is what I have now

$('.PointsToggle').live('each',function() {
              $this = $(this);
              if ($this.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
                $this.width(510);
              } else {
                $this.width(20);
              }
            })

But this doesn't seem to work now

Any ideas?

Thanks

Jamie

A: 

I think you probably want to replace '$this' with a 'var thisObject':

$('.PointsToggle').live('each',function() {
          var thisObject = $(this);
          if (thisObject.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
            thisObject.width(510);
          } else {
            thisObject.width(20);
          }
        })
mrjames
+1  A: 

You can only bind event handlers with .live(), which 'each' is not. This should work:

$('.PointsToggle').live('load', function () { $(this).each(function () { ... }); });
tandu
Doesn't work http://www.jsfiddle.net/vn4g4/
Shay Erlichmen
Hmm that's a tough one. I'm not sure what even handler to use. In the click function, I chained .ready() to .appentTo() and that seemed to work, but it seems strange to me.
tandu
+1  A: 

For this sort of thing you will need the livequery plugin

$('.PointsToggle').livequery(function() {
  var $this = $(this);
  if ($this.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
    $this.width(510);
   } else {
    $this.width(20);
   }
})
Shay Erlichmen