Recently at work, because a plugin must use Jquery-pack.js, and this package is very old jquery, so the function is not used, such as the $ () selector and the parent () can not get the contents of the label.
So there is no way, only native JavaScript, in order to achieve this function, I have to use the HTML tag class to get the DOM structure of the tag.
In JavaScript built-in core, the document object and the element object can be in a total of three ways to obtain the following elements, namely: getElementById (' id '), getelementsbyname (' name '), getElementsByTagName (' tag ').
However, when designing a Web page, the class that most often needs to be used does not have a corresponding method to get the same classname elements.
But we can write one ourselves, the code is very simple:
function Getelementsbyclassname (tagname,classname) { var tag = document.getElementsByTagName (tagName); var tagall = []; for (var i = 0; i<tag.length; i++) { if (Tag[i].classname.indexof (className)! =-1) { tagall[tagall.length] = ta G[i]; } } return tagall; }
The principle is to get the contents of the tag by getting the specified label, using getElementsByTagName to obtain the content of the label, and then comparing it to the parameters passed in according to the classname of the label, and then returning it if the equality is placed in the array.
Use native JavaScript to simulate getelementbyclassname.