1

I am working on a javascript library, The library syntax will go as follows: tex(selector).function(specifier). Here is what I have so far:

(function(){
    var tex = function(selector,context){
                //code

    },
    tex.prototype = {
         show: function () {
             this.style.display = "inherit";
             return this
         }
    };
    window.tex = tex
})();

The problem I am having is how do I set this to the element. Does anyone know how I can do that the jQuery way?

Thank you all for your help.

2
  • 1
    Look at the jQuery source and see how it does it. Commented Oct 12, 2013 at 0:06
  • @Barmar I have but it is hard for me to understand. That is why I am asking the question. Commented Oct 12, 2013 at 0:08

1 Answer 1

1

Maybe try :

if (document.querySelectorAll(selector==null || undefined) {
//nothing there

} else {
tex = document.querySelectorAll(selector);
}
Sign up to request clarification or add additional context in comments.

2 Comments

Sorry but that sets the value of itself, jQuery somehow sets this to the element. You still get an upvote for trying.
According to the spec, this returns a node list of the marched elements, not set the values: developer.mozilla.org/en-US/docs/Web/API/… I updated my answer to use querySelectorAll to not just return the first element, but all found

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.