Skip to content

Commit

Permalink
Merge pull request #25 from codler/patch-2
Browse files Browse the repository at this point in the history
Fix #24 Implement Document.getElementsByClassName
  • Loading branch information
kethinov committed Mar 2, 2020
2 parents 029ac01 + 853178b commit 7c54a0b
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,21 @@ Document.prototype = {
return rtv;
},

getElementsByClassName: function(className) {
const pattern = new RegExp(`(^|\\s)${className}(\\s|$)`);
return new LiveNodeList(this, base => {
var ls = [];
_visitNode(base.documentElement, node => {
if(node !== base && node.nodeType == ELEMENT_NODE) {
if(pattern.test(node.getAttribute('class'))) {
ls.push(node);
}
}
});
return ls;
});
},

//document factory method:
createElement : function(tagName){
var node = new Element();
Expand Down

0 comments on commit 7c54a0b

Please sign in to comment.