0

I'm wondering, why do some elements appear like an array and others like HTMLSpanElement. I've attached a picture as I'm not sure how to describe this otherwise.

The following log is made via

log(returner);
log(returner[0]);

console logging

1
  • returner is window.getElementsByClassName('doi'); Commented Feb 8, 2012 at 23:56

3 Answers 3

1

Is returner a jQuery object as a result of $() ? $() will always return an array, even if there is one or zero elements inside of it. Without specifying an index in your first console.log, the entire contents of the array are outputted. In the second console.log, you include an array index, so only the element matching that index is outputted.

Sign up to request clarification or add additional context in comments.

1 Comment

More generally, the OP is comparing an array returner with an element in the array returner[0]. jQuery is moot. (though I agree the likely originator)
1

Because the element that appears like an array IS an array - it's an array of DOM element objects (HTMLSpanElement, etc).

When you log the first element of the array with returner[0], that element is a DOM object, so it logs it as an object.

Comments

1

Because (it looks like) returner is not an element, but an array of elements.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.