I would like to add another div within a div group on a button click in order to have a continuously generating slider. Like so:
<div class="carousel-items">
<div class="date-carousel-other slider"></div>
<div class="date-carousel-other slider"></div>
<div class="date-carousel-other slider"></div><!-- new div -->
</div>
Currently my java script is:
$('.slick-next').click(function(){
$('"<div class="date-carousel-other slider"></div>"').append( ".carousel-items" );
});
The result is appending the boxes underneath my slider (big div) instead of inside the slider. Appending to ".slider"
instead, duplicates all the div's and wedges boxes inside the slider.
Is my syntax off or am I using the wrong method?
As per Docs,
The .append() and .appendTo() methods perform the same task. The major difference is in the syntax-specifically, in the placement of the content and target. With .append(), the selector expression preceding the method is the container into which the content is inserted. With .appendTo(), on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted into the target container.
So your solution failed because .append()
expects the target as selector and content as argument in method .append()
. Like this,
$('.slick-next').click(function(){
$(".carousel-items").append('<div class="date-carousel-other slider"></div>' );
});
if you want to keep the target and content in same way,use .appendTo()
instead of .append()
:
$('.slick-next').click(function(){
$('<div class="date-carousel-other slider"></div>').appendTo( ".carousel-items" );
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With