Home > Web Front-end > JS Tutorial > body text

js gets the node array of multiple tagnames_javascript skills

WBOY
Release: 2016-05-16 17:22:00
Original
924 people have browsed it

For functional needs, I wrote a small method to obtain a collection of multiple tagname nodes. Similar to the effect of jQuery's $('iput,select,textarea','#form'), the nodes are returned in the order they are in the original document stream.

Copy code The code is as follows:

//Get the node array of the specified tag type Use case: GetTagNames ('input,select,textarea',document.getElementById('form'))
function GetTagNames(tagnames,parEl){
//The parent node is not defined and the default loop document
var parEl=parEl || document;
//Get the child nodes of the specified parent element
var all=parEl.getElementsByTagName('*');
//Store all qualified child nodes
var nodes=[];
//Convert the transferred tagname into a regular judgment
var reg=eval('/' tagnames.split(',').join('|') '/i');
/ / Loop, judge, store
for(var ii=0;ii if(reg.test(all[ii].nodeName)){
nodes.push( all[ii]);
}
}
//Return
return nodes;
}

From: mrthink.net

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!