This is the plugin:
(
function($)
{
$.fn.foo=function()
{
$(this).focus()
return $(this)
}
}
)(jQuery)
Now, $('input#foo').foo()
does not get focus. Any idea why?
This is the plugin:
(
function($)
{
$.fn.foo=function()
{
$(this).focus()
return $(this)
}
}
)(jQuery)
Now, $('input#foo').foo()
does not get focus. Any idea why?
Looks like your foo function expects a parameter:
$('input#foo').foo("mymap");
(function($){
$.fn.foo= function(map){
return this.each(function(){
// element-specific code here
$(this).focus();
});
};
})(jQuery);
more about Plugin Authoring.
Use $(this)[0].focus();
$().focus()
fires the events bound to focus
for a particular element. $()[0].focus()
calls focus on the DOM element itself, which causes the browser focus to change.