Skip to content

Commit

Permalink
Fix #24 Implement Document.getElementsByClassName
Browse files Browse the repository at this point in the history
  • Loading branch information
codler committed Mar 1, 2020
1 parent 4eba783 commit ef4356b
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 ef4356b

Please sign in to comment.