I'm just starting to write my own plugin but I'm having a bit of difficulty in storing jQuery objects as instance variables. By this I mean, for example, in the following code:
$.widget("ns.slider", {
options: {
"selector": "li",
"selected": 0,
"delay": 1000
},
_create: function() {
var slider= this;
this.element.addClass("slider");
this.container = $("<div class=\"slider-container\"></div>");
this.container.height($(this.element).height());
$(this.element).wrap(this.container).css({
"position": "absolute",
"top": 0,
"left": 0,
"right": 0
});
this.container.css({"position": "relative", "overflow": "hidden", "backgroundColor": "#CCC"}); // Problem line
this.container.remove(); // Also problem line
}
}
The two lines I have marked as problem lines don't appear to execute - or rather they do, but the changes are not visible on the page. I'd expect to see the background colour to go grey on the first line and to disappear completely on the second. It seems like the wrap function actually duplicates the element and the duplicated element maintains the old properties when changes are made to the original. Yet I'm sure I've used this before, years ago, and it worked fine.
I'm using jQuery 1.8.3 with jQuery UI 1.10.4. Before anyone says it, I know there is already a jQuery UI slider - I had to rename the plugin for the purpose of this question for confidentiality reasons.
What am I doing wrong here? Please let me know if there is any additional information I should supply. Thanks in advance.
this.containeris being added to the DOM using dev tools - but anything called onthis.containerdoes not have any impact on the DOM element. I'll try calling a timeout in any case.