Possible Duplicate:
document.getElementById vs jQuery
I am learning jQuery and javascript.
-
I wonder why the
$()function of jQuery does not replace thedocument.getElementById()function of javascript. -
Isn’t it the role of
$()? -
If not, what’s the role of
$()?
I got to this question because $().outerHeight doesn’t work.
Thank you.
$accepts selectors, HTML strings and regular JS objects.getElementByIdonly accepts theidattribute of an element. They do different things.You’re trying to access a DOM object property, but from a jQuery object. jQuery objects wrap DOM objects, but they don’t replace them.
To access the DOM object, you can use
$(...)[0](or$(...).get(0)) and your code should work just fine: