in jQuery you can do something like this:
var domElement = document.getElementById("myId");
var tmp = jQuery(domElement);
upon which you can get the node
var node = tmp[0];
I would like to know how something like this can be done in native javascript.
Regards
in jQuery you can do something like this:
var domElement = document.getElementById("myId");
var tmp = jQuery(domElement);
upon which you can get the node
var node = tmp[0];
I would like to know how something like this can be done in native javascript.
Regards
Share Improve this question edited Mar 10, 2014 at 8:00 Felix Kling 818k181 gold badges1.1k silver badges1.2k bronze badges asked Mar 10, 2014 at 7:39 user1221121user1221121 1-
Honest question: What did you think
domElement
was and what the difference betweendomElement
andnode
was? Assuming you knew thatdocument.getElementById
is the DOM API, not jQuery. – Felix Kling Commented Mar 10, 2014 at 8:01
3 Answers
Reset to default 1Your domElement variable is the node of the DOM tree. That tmp variable wraps it into a jQuery object and the [0] indexer gets the DOM element back. So the native JavaScript is the first line of your code.
var domElement = document.getElementById("myId");
here you get the DOMelement
or DOM Node
var tmp = jQuery(domElement);
here you get the DOM element
wrapped in jQuery
. So its like DOM Element
wrapped in jQuery so that jQuery
functions can applied to it.
In effect there is no difference between DOM element
and node
in native javascript.
In short var node = document.getElementById("myId");
is exactly what you want to do in your code with naive javascript.
To explain, in var domElement = document.getElementById("myId");
you are referencing the node with myId
to domElement
, then with var tmp = jQuery(domElement);
, you get that dom element as jquery object.
var node = tmp[0];
selects first child of tmp
as dom element which in conclusion equals to
document.getElementById("myId")
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745443759a4627950.html
评论列表(0条)