Changing the css of objects in a array

rikuto148

I'm woking on a jQuery personal project and I created an array and trying to edit the position of each object in the array with .css but Im getting an error. I feel like Im doing something simple wrong.

http://codepen.io/mat148/pen/KwMbZR

The line in question is:

$(circleArray[5]).css('top','5px');
Ma Cheng

Try it:

//global var
var circleArray=[];

$(window).load(function() {
    var circle = '<div class="circle"></div>';
    $(window).keypress(function(e){
        if(e.which == 99) {
            var circleNum = parseInt( prompt("input number of elements wanted"),10 ) ;
            for(var a=0; a<circleNum;a++ ){
                var $circle = $(circle);
                $circle.css('top','5px').appendTo('.holder');
                circleArray.push($circle);
            }
            console.log(circleArray);
        }
    });
});

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事