How does jquery obtain the name of an element such as <div id = "aa"> dd </div>?
$ ("# Aa"). xxxmethod returns to "div"
How does jquery obtain the name of an element, such as <div id = "aa"> dd </div>?
$ ("# Aa"). xxxmethod to get "div"
[Kunming] Si Xue Chuan Qiong (447031499) 13:35:50
$ ('# Elementid'). get (0). tagName
$ ("# Aa") [0]. tagName.
JQuery obtains the Tag Name
Copy codeThe Code is as follows:
$ ('# Elementid'). get (0). tagName
Here, the tag name is capitalized, for example, A, DIV.
Background:
Conversion between jQuery objects and dom objects
Only jquery objects can use methods defined by jquery. Pay attention to the differences between dom objects and jquery objects. When calling methods, pay attention to dom objects or jquery objects.
Common dom objects can be converted to jquery objects through $.
For example, $ (document. getElementById ("msg") is a jquery object. You can use the jquery method.
Because the jquery object itself is a set. Therefore, if a jquery object is to be converted to a dom object, You must retrieve one of them. Generally, you can retrieve it through indexes.
For example: $ ("# msg") [0], $ ("div "). eq (1) [0], $ ("div "). get () [1], $ ("td") [5] are all dom objects. You can use methods in the dom, but you cannot use Jquery methods.
The following statements are correct:
$ ("# Msg" cmd.html ();
$ ("# Msg") [0]. innerHTML;
$ ("# Msg"). eq (0) [0]. innerHTML;
$ ("# Msg"). get (0). innerHTML;