1

画像から div に表示する単純なフェード コンテンツ スライダーがあります。問題なく動作しますが、追加したいのは次のとおりです。

  1. (直接の) 子要素を数える
  2. 親div(クラス名「showContainer」)にドットホルダー(クラス名「imgdotholder」のdiv)を追加します。
  3. div 内の子ごとにドット (クラス名「imgdots」の div) を追加します。

マークアップの例:

<div class="showContainer">
    <div>Direct Child element 1</div>
    <div>Direct Child element 2</div>
    <div>Direct Child element 3</div>
</div>

これは私がこれまでに得たすべてです。どんな助けも大歓迎です!

var imgCount = $('.showContainer').childern().length;
$('<div class="imgdotholder"><div class="imgdots"></div></div>').appendTo('.showContainer');

編集何かを追加するのを忘れました : マークアップの例:

<div class="wrapper">
    <div class="showContainer">
        <div class="blah">Direct Child element 1</div>
        <div class="blah">Direct Child element 2</div>
        <div class="blah">Direct Child element 3</div>
    </div>
</div>

私の問題を再実行するには、次のことを行う必要があります: 1) 「showContainer」div の子要素を数える必要がある 2) 次に、「imgdotholder」という div を「wrapper」div に追加する必要がある 3) 内部「imgdotholder」divの各画像にドット(「imgdots」と呼ばれるdivで表される)を追加する必要があります-3つの画像があるとしたら、3つのドットを追加する必要があります

基本的なセットアップを備えたjsfiddleは次のとおりです。http://jsfiddle.net/Reinhardt/cgt5M/

4

3 に答える 3

0

ということですか

$('.showContainer').children().each(function(){
    $(this).appendTo('<div class="imgdots"></div>');
});

編集

わかったか見てみよう

// Count of the direct children of .showContainer , If you need
var imgCount = $('.showContainer').length;

// Append the .imgdotholder to the .wrapper
$('.wrapper').append('<div class="imgdotholder"></div>');

// Iterate over all the children and in each step append an .imgdots to the .imgdotholder
$('.showContainer').children().each(function(){
    $('.wrapper .imgdotholder').append('<div class="imgdots"></div>');
});
于 2013-10-09T11:24:40.267 に答える