Reputation: 10691
How do I fade in an element after using jquery's .before?
jQuery
$('.button').on("click", function(event){
var html = '';
html = '<div class="row new">Test</div>';
$('.content .row:first').before(html);
});
HTML
<a class="button">Insert me and fade me</a>
<div class="content">
<div class="row"></div>
<div class="row"></div>
<div class="row"></div>
</div>
Upvotes: 1
Views: 2173
Reputation: 207916
Add this line: $('.row.new:last').hide().fadeIn();
jQuery:
$('.button').on("click", function(event) {
var html = '';
html = '<div class="row new">Test</div>';
$('.content .row:first').before(html);
$('.row.new:first').hide().fadeIn();
});
Upvotes: 1
Reputation: 9847
$('.button').on("click", function(event){
var html = '<div class="row">Test</div>';
$('.content .row:first').before(html).prev().hide().fadeIn(1000);
});
The new
class is unnecessary. You already know that the first row is the new one (and you would have to remove the class upon subsequent insertions).
Upvotes: 1
Reputation: 2082
$(function() {
$('.button').on("click", function(event){
var html = '';
html = '<div class="row new">Test</div>';
$('.content .row:first').before($(html).fadeIn());
});
});
Upvotes: 5