Here’s the code of my plugin..
$.fn.slide = function(settings) {
return $(this).each(function() {
setInterval(function() { $.slider(opt.direction , opt.slideSpeed,this) }
}
jQuery.slider = function(direction,slideSpeed,elm) {
console.log(elm) - > shows DOMWindow[] window as object
}
}
script.js
$('#container').slide({
slideAnimationTimeInterval : 6000,
slideSpeed : 700,
});
console.log(elm) – > shows DOMWindow[] window as object but i need #container object how can i get it ?
When nesting functions, you need to save
thisin another variable like this:thisis the context of the function, by default it’s the global objectwindow. jQuery sets it to something more useful when calling a function (e.g. an element in.each()). However, when your interval function is called,thisis unbound again (=>this === window). By saving it in a custom variable, it’s preserved in the closure of your function.