2013-02-07 4 views
0

를 사용하여 DOM에 동적으로로드 된 내용을 이동 - squarespace 6 .CSS내가 블로그 템플릿을 사용하고 JQuery와

마다에 나에게 .html 중에서 액세스 /과 제한된 액세스를 허용하지 않는 I 블로그 게시물을 만듭니다. 태그와 카테고리를 태그에 추가합니다.하지만 태그/카테고리는 블로그 게시물 하단에 있습니다. 나는 그들을 사이드 바에 옮기려고 노력하고있다.

$(document).ready(function(){ 

var $categories = $('div.categories').parent('article'); 
var $spanDate =('span.date').parent('article'); 

$categories.insertBefore($spanDate); 

}); 
:

문제는 내가 페이지에 여러 블로그 게시물을 가지고있다, 나는 .tags.category 클래스를 선택하기 위해 jQuery를 사용하여 다음과 같은 코드로 .date 전에 .sidebar로 이동하기 위해 노력하고있어

문제는이 코드는 모든 블로그 게시물에서 태그/범주를 잡고 카테고리와 태그가 혼합지고, 그래서 모든 사이드에 적용입니다 (이 코드는 .categories에 대해서만 예이다).

부모 기사의 .tags.category을 선택하고 해당 코드로 이동하도록 코드를 가져 오려고합니다. 같은 부모의 sidebararticle.

모든 블로그 게시물에 적용되기를 원하기 때문에 특정 ID를 사용할 수는 없지만 태그/카테고리는 해당 게시물 내에 있어야합니다. 내가 바로 당신을 이해 해요 경우

<blog> //Wrapper for the whole blog page 
<content> 
<article> //Each article is a blog entry 
    <section class="main"> //Contains the contents of the blog entry. This also has a dynamically generated ID, 
    //Blog Entry Content Goes Here 
    <footer> 
     <div class="meta"> //Contains the tags/categories I try to pull out of the DOM 
     <span class="tags"></span> //Contains the tags each wrapped in an `<a>` 
     <span class="categories"></span> //Contains the category tags 
     </div> 
    </footer> 
    </section> 
    <section class="sidebar"> //This is where I'm trying to place the tags/categories 
    <span class="date"></span> //I try to place the category before this in the jquery code above 
    <more spans....> // I try to place the tags appended onto the end of the sidebar (code not shown above). 
    </section> 
</article> 
<article></article> //More blog entries with same structure 
<article></article> //More blog entries with same structure 
<article></article> //More blog entries with same structure 
</content> 
</blog> 
+0

html의 샘플을 보는 것이 도움이 될 것입니다. –

+0

@James는 html 구조체를 추가했습니다. 처음부터 그 부분을 넣었어야합니다 – pappley

+0

jquery 호출에서 컨텍스트로 각 기사를 사용하고 기사를 사용하려고 했습니까? like (더미 코드) $ ('articles'). 각 (function (articelElem) {$ ('div.categories', articelElem) ....}) –

답변

0

,이 수행해야합니다 다음과 같이 삽입 된 코드를 많이하지만, HTML의 기본 구조가있다

이다

$('div.categories').each(function(){ 
    var $this = $(this); 
    var $date = $this.closest("article").find(".date"); 

    $this.insertBefore($date); 
}); 

열쇠는 각 .categories에 대해 .date이 아닌 관련 .date을 찾았습니다. 또한, 당신의 코드는 제공된 html로 어떤 것도해서는 안된다. .categories 또는 .date에는 직접 상위가 article입니다.

관련 문제