June 15, 2013

.fadeto() not working for dynamic class in jquery

User2488882’s Question:

My Code is like this.

<script>
var i=0;
$(window).load(function() {
  $(function() {
   setInterval(update, 1000);
  });
  function update() {
  i++;
  setTimeout(function(){$("#container").after($('<div>',{text:'Hello',class:'test'+i}))},100);
   $("#container .test"+i).delay(500).fadeTo('slow',0);
  }
});
</script>

.after() seems working.
But .fadeto() doesn’s work.

I know there are utilities for dynamic classes like .on() and .live() .
But I dont know how can .fadeTo be working for dynamic classes.

Any ideas?

Try it this way:

$("#container").find(".test"+i).delay(500).fadeTo('slow',0);

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!