0
$(function(){
	$('.table_pay').dblclick(function(){
		
		if($('div', this).is('.value')){
			var v = $('.value', this).html();
			$('.value', this).remove();	
			$(this).append("<input type='text' name='val' class='field'>");
			$('.field', this).attr('value', v);
			$('.field', this).focus();
			$('.field', this).focusout(function(){ 
				var val = $(this).attr("value");
				$(this).remove();	
				$(this).append("<div class='value'>"+val+"</div>");
			});
		}
		
	});
});

What to do on the 13th line that the reference object which is on the 2nd line (the class named "table_pay") will be its reference call..

please help me guys, need it ASAP.

Any suggestions will be very much appreciated! Thanks!

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Airshow
0

Tinker,

Your code and question are both difficult to follow.

Can you post a corresponding HTML snippet so I can see what you are trying to achieve?

Airshow

0

what i am plotting at is the reference object of this code

$(this).append("<div class='value'>"+val+"</div>");

which will be found at line 13, and it is not working well cause its referring to this object

$('.field', this).focusout(function(){

which also be found at line 10: the question is what should i do to this "$(this)" code that it would refer to this object

$('.table_pay').dblclick(function(){

which can be found at line 2, so that when that element will be triggered only that triggered element where will the new DIV will append.

0

Tinker,

I still can't see what the code is trying to achieve, but I understand that you need to refer to an outer this in an inner function with its own this .

The standard solution is to set var that = this; (at your line 2). Through closure, that remains available to any inner function(s) that use it (whilst still allowing each inner function to access its own this if required).

By setting var that = this; , var that2 = this; etc. at successive levels of nested function, each level can make its this available to all inner functions regardless of level. That said, it is seldom necessary to need more than two levels (outer and inner).

Airshow

Edited by Airshow: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.