Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What type of DOM Element?

Tags:

html

jquery

dom

e.g. if i have this: <div id='mydiv'>whatever</div> 

then let say in jQuery, how can I find out that the dom element with id "mydiv" is a DIV or is some other element type.

e.g.  $('#mydiv').????  ? 
like image 630
murvinlai Avatar asked May 24 '11 17:05

murvinlai


People also ask

What is the type of a DOM element in JavaScript?

The Element type represents an XML or HTML element, providing access to information such as its tag name, children, and attributes. the element's tag name. may be a Document or Element.

How many DOM elements are there?

While browsers can handle larger DOM trees, they are optimized for a maximum of 32 elements deep. A large DOM tree can harm your page performance in multiple ways: Network efficiency and load performance.

How many DOM types are there?

Few people know about that. We are not going to touch that node, we even don't draw it on diagrams, but it's there. The document object that represents the whole document is, formally, a DOM node as well. There are 12 node types.

How do I identify a DOM element?

The easiest way to find an HTML element in the DOM, is by using the element id.


1 Answers

var type = $('#mydiv')[0].tagName  alert(type); //displays "DIV" 
like image 98
John Strickler Avatar answered Oct 19 '22 04:10

John Strickler