Issue
How does the click event work in JQuery?
I mean, I learned how to make chaining method but I have no idea of how make the click event like this:
MyLibrary("selector").click(function(){
console.log("hello");
});
I guest that if I learned this, i'll know how does blur
, mouseover
, etc etc, works as well.
Please I hope you help me learn, I searched for answer but i could not find any or maybe I was asking in the wrong way.
UPDATE
I know how to use jQuery, BUT WHAT I ASKED WAS how can I make it? I mean, I want to create a library and I want to add a click event like jQuery does.
I did chaining method like this:
Find().UserByName("Bob").Write("DivOrInputObject's ID").UserByPass("pass").Write("DivOrInputObject's ID");
But while writing the code, It came to my mind how can I make a click event? In simple words, I want to imitate click()
event like jQuery does and add it to my library.
Solution
I am assuming that you are writing your own jQuery. So if your MyLibrary object have selected element under MyLibrary.el then you can have chainable click handler like this:
click: function(handler){
this.el.addEventListener('click', handler.bind(this.el));
return this;
},
This will bind this
inside the handler to the element itself. Just like jQuery
Here is this code in action: http://jsbin.com/ahinow/1/
Answered By - Mohsen Answer Checked By - Robin (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.