Hello I'm trying to detect focusing the element using namespace. Here`s my working code:
(function($){
searchBox = {
element: $('div#block-search-form input[name=search_block_form]'),
focus: function(){
this.element.live('focusin',function(){
console.log('in');
});
this.element.live('focusout', function(){
console.log('out');
});
}
}
$(document).ready(function(){
searchBox.focus();
});
})(jQuery);
My question is how to make it without using the .live()?
EDIT
To make it work I had to make an element as a function and now everything works fine. When I haven't it hasn't have the correct context. My new code:
(function($){
searchBox = {
element: function(){return $('div#block-search-form input[name=search_block_form]')},
init: function(){
this.focus();
},
focus: function(){
var that = this;
that.element().on({
'focusin': function(){
/*code*/
},
'focusout': function(){
/*code*/
}
});
}
}
$(document).ready(function(){
searchBox.init();
});
})(jQuery);