6

At the moment I have a running fiddle that I am trying to get a css3 opacity transition to fire off when I add a class to it. The basic set up is that I click a button and then through jquery I add a div to the dom and after I add that element to the dom I then add a class to it. The adding class to that new dom element is suppose to kick off my transition but it is not, the only thing that is happening is that the element is being showed but the opacity transition isnt working. Any help will be much appreciated, I am leaving a link to the fiddle here fiddle link .And yes I know i could do the fade in with just jquery, but this is just a experiment , that would probably be used to kick off other css transition other then opacity

2
  • It does indeed only seem to work if the class is predefined...adding it dynamically will not execute the transition. Maybe this is still a bug to be solved. Commented Oct 10, 2011 at 15:28
  • Thats what i was thinking to, but is till find it hard to believe that this has not been noticed by chrome or firefox dev's Commented Oct 10, 2011 at 15:39

2 Answers 2

9

I have encountered this problem before, the only workaround I've found is adding a setTimeout to let the DOM notice there's a new element. It can be zero ms and it will still work:

$('button').live('click', function() {
    $(this).after("<div class='fade'>This is just a test</div>")
    setTimeout(function(){$(".fade").addClass("in");}, 0)
});

http://jsfiddle.net/tfmFx/

Sign up to request clarification or add additional context in comments.

1 Comment

Well that is really annoying. Thanks for the solution.
0

I don't think CSS3 transitions are supported on dynamically created elements just yet. I tried modifying your sample by placing the div directly in the HTML, and the transitions worked fine. You might have to live with that as a workaround until browser support improves.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.