I’ve come across this line and I can guess what it’s doing but shouldn’t there be a length > 0 on the children or will it always return/can be used as a boolean?
Or does jQuery’s children return a boolean, or is this person relying on the existence of the returned children?
append(($(this).children()) ? '<div class="vAlignWrapper" style="overflow: hidden;">' + $(this).html() + '</div>' : ' ').
I’m trying to debug a large JS file and I’m trying to make sure each line does what its supposed to do.
Like most jQuery methods,
children()returns a jQuery object for chaining. If there are no children, it returns an empty jQuery object.If you want to know if any children exist or not, you MUST use the
.lengthproperty, which returns a number greater than zero if there are any and zero if there aren’t.So, yes — it appears the original code was incorrect. Testing
$(this).children()as a Boolean value will always be consideredtrue.