<div>1</div>
<div>2</div>
<div>3</div>
<script>
function $() {
return {
id: function (id) {
document.getElementById(id);
this.id = id;
return this;
},
write: function (write) {
document.getElementById(this.id).innerHTML = write
return this;
},
add: function (add) {
document.getElementById(this.id).innerHTML += add
return this;
},
html: function () {
return document.getElementById(this.id).innerHTML
return this;
},
src: function () {
return document.getElementById(this.id).src
return this;
},
tag: function (tag) {
return document.getElementsByTagName(tag)
this.tag = tag
return this;
}
};
}
alert($().tag('div')) // Object NodeList
</script>
Не понял что циклом надо делать, дело в том что write(),html(),add(),src(). У них при обращении к элементу стоит document.getElement
ById(this.id) Можно ли как то проверять, что было вызвано: id() или tag()? И заменять document.get
ElementById(this.id)(
ElementsByTagName(this.tag))?