开发者

Number of Children in Wrapper Chosen by Sorting Script

    var $this = $(this);
    var target = $this.hasClass('To_A') ? '#Section_A'
               : $this.hasClass('To_B') ? '#Section_B'
               : $this.hasClass('To_C') ? '#Section_C'
               : null;

    var XofField = ($(target).length()) * 88;

I have a script that moves an element to a specific place in the DOM based on it's class. I need to know how many children are already in that target location, for the purpose of a css left property.

The last line of the above code does not work. Since the location varies, i felt that using target would be convenient.

*Should count new c开发者_开发技巧hildren that are created dynamically.

SOLUTION

var sectCount = $(target + " img").length;

Looking back i realize how simple the solution actually was... -__-"


length is a property, not a method. Also, you want children.

$(target).children().length


try to use $(target).children().length * 88; instead

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜