Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. (function () {
  2. function MyQuery(selector) {
  3. if (!(this instanceof MyQuery)) {
  4. return new MyQuery(selector);
  5. }
  6.  
  7. this.nodes = document.querySelectorAll(selector);
  8.  
  9. for (var i = 0; i < this.nodes.length; i++) {
  10. this.nodes[i] = this.nodes[i];
  11. }
  12.  
  13. }
  14.  
  15. MyQuery.fn = MyQuery.prototype = {
  16. parent: function () {
  17. return this.nodes[0].parentNode;
  18. },
  19. color: function(setColor) {
  20. this.nodes[0].style.color = setColor;
  21. return this;
  22. }
  23. };
  24.  
  25. window.myQuery = window.$ = MyQuery;
  26.  
  27. })();
  28.  
  29. myQuery(".mySpan").parent();
  30.  
  31. // Returns .. <div>
  32.  
  33. myQuery(".mySpan").parent().color("red");
  34.  
  35. // TypeError: myQuery(...).parent(...).color is not a function
  36.  
  37. <div>
  38. This DIV has some content.
  39. <span class="mySpan">This is a span</span>
  40. more content here.
  41. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement