Friday, 27 September 2013

Does a jQuery object have a property that points to a corresponding JavaScript object

Does a jQuery object have a property that points to a corresponding
JavaScript object

Being curious. jQuery is written on top of JavaScript. So, for a given
selected DOM element, does jQuery keep a property (attribute) that acts as
a handle to the corresponding (internal) JavaScript DOM object? If so,
what property in the jQuery object acts as a handle to the corresponding
JavaScript object.
To facilitate further, I have quickly written an example at jsfiddle:
http://jsfiddle.net/mMvaD/1/ . The example basically retrieves a DOM
object using both jQuery and prints its (enumerable) properties. Could
someone point me to the property in the jQuery object points to a
JavaScript object, if we have one? For the sake of completeness, I have
also shown properties belonging to a corresponding JavaScript object.
Here is the code:
<html>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
<body>
<div id="idDiv"></div>
<script type="text/javascript">
$(document).ready(function() {
$("body").append("jQuery Object:<br>");
elem1 = $("#idDiv");
for (var item in elem1) {
$("body").append(item + ", ");
}
$("body").append("<br><br>JavaScript Object:<br>");
elem2 = document.getElementById("idDiv");
for (var item in elem2) {
$("body").append(item + ", ");
}
});
</script>
</body>
</html>

No comments:

Post a Comment