I want to get nodeType and then compare it to where it is text node or element node.
As noted above, $('.jj').get(0).nodeType
works.
Same as $('.jj').first().nodeType
or $('.jj').prop('nodeType')
.prop()
: Get the value of a property for the first element in the set of matched elements or set one or more properties for every matched element.
To get the DOM Node you can use [0]
:
var mm = $(".jj")[0];
if (mm.nodeType === 1) {
// Node.ELEMENT_NODE
}
However, <div>
element will never be a text node and won't have a nodeValue
.
Text node is the first child of your <div>
element. So the following code will give you "value":
alert(mm[0].firstChild.nodeValue);
I know it wasn't the question, but to see what type it is (DIV, SPAN, etc), use tagName.
var mm = $('.jj').get(0);
alert(mm.tagName);
<script type="text/javascript">
$(function(){
var mm= $('.jj')
alert(mm.get(0).nodeValue)
})
</script>
or
<script type="text/javascript">
$(function(){
var mm= $('.jj')
alert(mm[0])
})
</script>
Because a jquery collection is a "wrapped set" of DOM elements.
try to access to those properties with
var mm = $('.jj').get(0);
alert(mm.nodeValue);
alert(mm.nodeType)