admin管理员组文章数量:1327524
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" );
本文标签: javascriptAppending an HTML div inside another divStack Overflow
版权声明:本文标题:javascript - Appending an HTML div inside another div - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742177032a2427765.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论