jQuery live function not working
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
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);
}
})
You can only bind event handlers with .live()
, which 'each' is not. This should work:
$('.PointsToggle').live('load', function () { $(this).each(function () { ... }); });
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);
}
})
you can use each method in a event like click that mean which you can use this method in a body of a event like this
$("#Prefactor_save").live('click', function () {
var tmp = "";
alert(tmp);
$("#factor_tb td").each(function () {
tmp += $(this).val() + ",";
});
$("#factor_tb selected:option").each(function () {
tmp += $(this).text() + ",";
});
alert(tmp);
});
in this sample I use each function in a click event.
精彩评论