2017-05-03 117 views
0

我想写一个jQuery代码,将'项目内容'类的文本追加到'.projects文本'(而不是追加“你好世界”的段落)jQuery从一个类追加元素

$(".projects-carousel .owl-nav").click(function(){ 
 
     $('.projects-text').append('<p>Hello world</p>' 
 
) 
 
    });
<div class="projects-Wrapper"> 
 
    <div class="projects-content"> 
 
    <h3> This header should append in projects-text div </h3> 
 
    <p>This is the text should append in projects-text div as well</p> 
 
    </div> 
 
    <div class="projects-img-wrapper"> 
 
    <a class="popup-youtube" href="#"><img src="img/projects/1.png" alt="Jey The Dog"></a> 
 
    </div> 
 
</div> 
 

 
    <div class="projects-text"> 
 
    
 
    <!-- Here should a text from ".projects-content" append --> 
 
    
 
    </div>

回答

1

您可以使用jquery的方法html来获取设置html内容的&。它将包含HTML标签。如果您只想获取文本,则可以使用text方法。 替换此

$('.projects-text').append('<p>Hello world</p>'); 

$('.projects-text').html($('.projects-content').html());