$(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!

Recommended Answers

All 5 Replies

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

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.

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

Wow! thanks a lot Airshow. It works!!

Wow! thanks a lot Airshow. It works!!

:cool:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.