jqueryを使用して、Rel Attibuteを投稿に自動的に適用します
質問
編集:つまり グループ化 同じことを与えるように REL
すべての人に執着してください IMG
同じ投稿にsがありますが、各投稿には異なります REL
この質問の最後の例として。
だから、私は次のことをする必要があります:
<div id="Blog1" class="widget Blog">
<div class="blog-posts hfeed">
<div class="post hentry uncustomized-post-template">
<a name="8829400899632947948"/>
<div class="post-body entry-content">
<div id="8829400899632947948">
<div class="separator">
<a imageanchor="1" href="/images/outta.png">
<img src="/images/outta.png"/></a></div></div>
<div style="clear: both;"/>
</div>
<div class="post-footer">
</div></div></div></div>
jqueryとcolorboxを使用しています。最初の二つ DIV
sはポストコンテナです。グループ化する必要があります IMG
それぞれにs <div class="post hentry uncustomized-post-template">
を使用して REL
属性、次のようなもの:
1-投稿
1.1 -img -rel = "group0"
1.2 -img -rel = "group0"
1.3 -img -rel = "group0"
1.4 -img -rel = "group0"
2-投稿
2.1 -img -rel = "group1"
3-投稿
3.1 -img -rel = "group2"
3.2 -img -rel = "group2"
私は試してみました HAS
, PARENT > CHILDREN
と CHILDREN()
jqueryから REL:
ColorBoxから、しかし、私はロジックのどこかに欠けているようです。
誰かが私を助けることができますか?
解決
これはあなたが意味するものですか?
// 'walk' through every element that has class 'post'
// passing the index of each element to variable i
$('.post').each(function(i) {
// on `this` element, find all children img
// to which add attribute 'rel' with a value of
// 'group' concatenated with the parent's index (i)
$(this).find('img').attr('rel', 'group' + i);
});
編集:いくつかのコメントを追加してください、これがjQueryで新しい人々に役立つことを願っています
所属していません StackOverflow