Sachin Prasad
Sachin Prasad

Reputation: 5411

jquery slidedown and hide issue

Please check this code:

 var data = $(".others-involved-div-wrapper-tobe-copied").html();
 data = '<div class="others-involved-div-wrapper" >'+data+'</div>';
 $(".others-involved-div-wrapper:last").after(data).slideDown("slow");
 if ($(".others-involved-div-wrapper").length > 1){
     $(".others-involved-div-wrapper:last .delete-more-others-involved").show();
 }

Here the slideDown effect is not working. The data is not seen if I do display none in div

data = '<div class="others-involved-div-wrapper" style="display:none;" >'+data+'</div>';

If I'm doing data = data.hide(); ,Its showing error hide is not a function.

I just need slidedown effect when that data value is appended.

Upvotes: 2

Views: 540

Answers (3)

Alexander
Alexander

Reputation: 23537

You can also refactor your code using a jQuery element creation construct.

$("<div/>", {
    "class": "others-involved-div-wrapper",
    "html": $(".others-involved-div-wrapper-tobe-copied").html()
}).hide().insertAfter("div:last").slideDown("slow");

Or, even use .clone().

$(".others-involved-div-wrapper-tobe-copied")
.clone()
.toggleClass("others-involved-div-wrapper-tobe-copied others-involved-div-wrapper")
.hide()
.insertAfter(".others-involved-div-wrapper:last")
.slideDown("slow");

Upvotes: 1

Scott Sword
Scott Sword

Reputation: 4718

Unless there is a reason that I'm unaware of, it appears that you are confusing jQuery with your variable assignments. Perhaps this might work for you:

 var content = $(".others-involved-div-wrapper-tobe-copied").html(),
     data = '<div class="others-involved-div-wrapper" >'+ content +'</div>';

 $(".others-involved-div-wrapper:last").after(data).slideDown("slow");

 if ($(".others-involved-div-wrapper").length > 1){

     $(".others-involved-div-wrapper:last .delete-more-others-involved").show();

 }

And @GautamJeyaraman is right, you can't apply a jquery method to a non jQuery object.

Upvotes: 1

GautamJeyaraman
GautamJeyaraman

Reputation: 545

data = data.hide() wont work because it is just HTML text and not a jquery object.

Check if

$(".others-involved-div-wrapper:last").after(data)

returns a jquert object. That might be the problem.

Upvotes: 2

Related Questions