javascript - How to get 'this' in a function referring to jQuery object -


amongst other things, have read:

but haven't solved 'this' problem i'm having piece of javascript.

i have section object gets passed xml uses populate section. in section object append div has specified index. resulting jquery object pushed sections array. following code section object code:

sections.push($('#section' + p_sectionindex)); this.showsection = function() {     this.show(); } this.hidesection = function() {     this.hide(); } sections[sections.length-1].on('show', this.showsection.call(sections[sections.length-1])); sections[sections.length-1].on('hide', this.hidesection.call(sections[sections.length-1])); 

elsewhere call sections[index].trigger('hide'); , sections[index].trigger('show');

the first of links mentioned above seemed suggest this in function depends on how it's called , pass reference this function using call. know showsection , hidesection function being triggered - can't this in functions refer jquery objects in sections array.

i have tried multiple variations of above (excluding call, using $(this) in functions, adding showsection , hidesection functions jquery object - amongst others) i'm kind of out of ideas.
appreciated!

this in event handler element node event bound to. if want jquery object wrapping node, use $(this)

demo: http://jsfiddle.net/b36m6/

this of course assumes revert correct way of passing function event binding.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -