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?
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?
Share Improve this question edited Jun 25, 2015 at 22:30 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Jun 16, 2015 at 11:16 jShoopjShoop 4111 gold badge6 silver badges15 bronze badges5 Answers
Reset to default 5As 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" );
});
Try with append()
$('.carousel-items').append("<div class='date-carousel-other slider'></div>");
or using .appendTo()
$('<div class="date-carousel-other slider"></div>').appendTo( ".carousel-items" );
You swapped it -
$(".carousel-items").append( "<div class='date-carousel-other slider'></div>" );
Or use appendTo
-
$("<div class='date-carousel-other slider'></div>").appendTo( ".carousel-items" );
You have swapped the positions of "Selector" and "Content". You must use append()
like below :
$('.slick-next').click(function(){
$(".carousel-items").append( '"<div class="date-carousel-other slider"></div>"' );
});
The append() method inserts specified content at the end of the selected elements.
Syntax:
$(selector).append(content,function(index,html))
You need to use appendTo()
instead of append()
, also remove unnecessary quotes ""
$('<div class="date-carousel-other slider"></div>').appendTo(".carousel-items" );