I have never understood some methods for directly using JavaScript For objects obtained through jQuery. Now I know about this case, the objects obtained by jQuery are not the same as those obtained by getElementById. So some new users... SyntaxHighlighter. all
I have never understood some methods for directly using JavaScript For objects obtained through jQuery. Now I know about this case, the objects obtained by jQuery are not the same as those obtained by getElementById. Therefore, some new users are confused about why $ {"# Element"} cannot be directly innerHTML. This is the reason. For the solution, see the following.
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 "))
This 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]
These are dom objects. You can use methods in 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;
From Zhang Yi ☆. Net★Java software alliance