Search code examples
zepto

how do I add custom function to zepto?


New to zepto (and honestly, far from a jQuery-whiz), I want to add a custom function.

This is my attempts so far:

//define..
$.fn.doSearch = function() { 
  alert(this.parentNode.html());
  //now xhr..
}
//assign..
$('#resetBtn').click( function (e) {$(this).doSearch()});

and

//define
<script type="text/ja..
function doSearch(obj) {
  alert('Ugly way but here I am');
}

//assign..
$('#resetBtn').click( function (e) {window.doSearch()});

And neither works.. I'd rather go the first route, aware that .fn isn't listed in the zepto-docs.

regards,

//t


Solution

  • ok, now I have

    //define
    var myFunc = {
      doSearch: function(obj) {
        //just check obj is ok.
        alert($(obj.parentNode).html());
      }
    }
    //correct way to extend zepto?
    $.extend($,myFunc);
    
    //assign...
    $('#searchBtn').click( function (e) {$(this).doSearch(this)});
    

    is this the way to go?