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
精彩评论