Forum Moderators: open
// Usage:
// $('foo').whatever('bar');
jQuery.fn.whatever = function(y) {
alert(this); // foo
alert(y); // bar
} // Usage:
// whatever('foo', 'bar');
function whatever(x, y) {
alert(x); // foo
alert(y); // bar
}
// Replace text contents with 'whatever... ' plus the string passed in
jQuery.fn.whatever = function (y) {
this.text('whatever... ' + y);
return this;
}
$('p').whatever('no soup for you!');
function whatever(x, y) {
$(x).text('whatever...' + y);
}
$('#body_con').on('swipeleft', function() {
$(this).css('left', '0');
}); I think I figured it out. Within the jQuery.fn.whatever I could use this, but within a function I had to use $(this).
$('#body_con') $('#body_con').on('swipeleft', function() {
// this == the element, not the jQuery object representing the element
// so to call jQuery method "css" on the element, need to wrap in jQuery object first
$(this).css('left', '0');
});