Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- function MyQuery(selector) {
- if (!(this instanceof MyQuery)) {
- return new MyQuery(selector);
- }
- this.nodes = document.querySelectorAll(selector);
- for (var i = 0; i < this.nodes.length; i++) {
- this.nodes[i] = this.nodes[i];
- }
- }
- MyQuery.fn = MyQuery.prototype = {
- parent: function () {
- return this.nodes[0].parentNode;
- },
- color: function(setColor) {
- this.nodes[0].style.color = setColor;
- return this;
- }
- };
- window.myQuery = window.$ = MyQuery;
- })();
- myQuery(".mySpan").parent();
- // Returns .. <div>
- myQuery(".mySpan").parent().color("red");
- // TypeError: myQuery(...).parent(...).color is not a function
- <div>
- This DIV has some content.
- <span class="mySpan">This is a span</span>
- more content here.
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement