2017-09-26 8 views
0

제대로 작동하지 않아 각 게시물에서 작동합니다. 독자가 당신이 어디에서 오는지 알 수 있도록 첫 번째 단락을 제외한 모든 단락을 둘러싸는 단락

https://jsfiddle.net/haymanpl/htuczx5q/

<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p> 

<div class="text"> 

<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p> 

이것은 워드 프레스 포스트의 예입니다

, 당신은 자신 또는 귀하의 사이트에 대한 정보를 넣어 이것을 수정할 수 있습니다. 마음에 들는 독자와 공유하기 위해 원하는만큼의 게시물을 작성할 수 있습니다.

</div> 

$("p:first-child").after(function() { 

    return '<div class="text">'; 

    }); 

이 작동하지만 내가 마지막으로 아이를 사용하여 추가 할 필요로 내가 원하지 않는 닫는 div 태그를 추가합니다.

$('p:first-child').after($('<div class="text">')); 

나는 첫 번째 부분을 제외한 div에 여러 개의 단락을 감싸려고합니다. 첫 번째 단락 뒤에 삽입 한 다음 마지막 단락 뒤에 삽입해야합니다.

+0

부분 또는 닫혀 있지 않은 태그는 삽입 할 수 없습니다. –

+0

"마지막 아이를 사용하여 추가해야하므로"하고 싶지 않습니다. 'span'에 하나 이상의 요소를 래핑하려고합니까? 그렇다면 질문을 업데이트하십시오. – fubar

+0

나중에 jquery에 대해'.wrap'을보십시오 – zgood

답변

1

여기에 내가 jQuery wrap을 사용했습니다 https://jsfiddle.net/htuczx5q/3/

$('p').not('p:first').wrap('<span class="text" />')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p> 
 

 

 
<p>This is an example of a WordPress post, you could edit this to put information about yourself or your site so readers know where you are coming from. You can create as many posts as you like in order to share with your readers what is on your mind.</p>

솔루션과 함께 할 것입니다. first paragraph을 제외한 paragraph을 모두 감쌀 것입니다.
$('p.className').not('p:first').wrap('<span class="text" />');

ID
$('p#id').not('p:first').wrap('<span class="text" />');

데이터 속성 클래스 이름

:

는 다음 세 가지 방법으로 수행 될 수있는 특정 포스트 (단락)을 타겟팅하는
$('p[data-attr="post1"]').not('p:first').wrap('<span class="text" />');

희망이 도움이 될 것입니다.

+0

그러나 모든 게시물에 영향을줍니다. 아카이브의 모든 게시물에 영향을주지 않고 각 단일 항목을 적용하는 코드가 필요합니다. – Dev

+0

@Dev 그럼 나는'classname' 또는'id' 또는'data-attribute'에 의해 게시물을 목표로 제안 할 것입니다. 도움이 될 대답을 업데이트하겠습니다. – Shiladitya

+0

큰 25 가지만 모든 게시물에 영향을주기 때문에 여러 게시물이 포함 된 보관소에서는 여전히 작동하지 않습니다. – Dev