0

I'm trying to set this code on new elements been added by jQuery using live()

var frcode = '<iframe scrolling="no"></iframe>';
$('.foo:nth-child(3n),.foo:last-child').after(frcode);
$('.foo:first').before(frcode);

I tried livequery plugin but not working good with me

the Livequery plugin i tried to use

$(".foo:nth-child(3n),.foo:last-child").livequery(function(){
   $(this).after(frcode);
});

$(".foo:first").livequery(function(){
   $(this).before(frcode);
});
Déjà Bond
  • 291
  • 4
  • 8
  • 32
  • Which version of Jquery you use? New jQuery does not have live, it use on instead – James Jul 11 '12 at 09:11
  • Also please post full code (better using jsfiddle) – James Jul 11 '12 at 09:12
  • [http://stackoverflow.com/questions/759887/how-to-create-a-dom-node-as-an-object](http://stackoverflow.com/questions/759887/how-to-create-a-dom-node-as-an-object) – Jith Jul 11 '12 at 09:12
  • @TrinhHoangNhu i'm using 1.7.2 ,,, about the live code will add it in a seconds – Déjà Bond Jul 11 '12 at 09:14

2 Answers2

1

You can listen to DOMSubtreeModified on a container where you put your created DOM elements into:

var frcode = '<iframe scrolling="no"></iframe>';

$('.container').on('DOMSubtreeModified', function(){
  $(this).find('.newElement:not(.processed)').after(frcode).addClass('processed');
})

(you could also use 'body' instead of '.container')

gherkins
  • 14,603
  • 6
  • 44
  • 70
0

If you are looking for only inserting new elements, you can also use DOMNodeInserted event.

See example of usage here: http://jsfiddle.net/2YSEP/

z0rch
  • 55
  • 9