bind click not working


I have this code in document.ready, my problem is that the bind click part is not working. I need to activate again when i press the button GUARDAR, any idea?

var counterCerrado = 0;
		$(this).html('<input type="text" value="'+$(this).text()+'"><button class="contador'+counterCerrado+'">GUARDAR</button>')
		counterCerrado = counterCerrado + 1

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Tom BeckCommented:
I don't understand the purpose of the counter. You will have to explain that.

Seems to me you could just use the same button to do whatever you have to do rather than create a new one with a unique class name. Add the input text box on the first click, remove it after parsing the input on the second click.

Something like this:
		if ($(this).hasClass('contador')) {
			// Run additional code to parse text box input
		} else {
		    $('<input type="text" value="'+$(this).text()+'" />').insertBefore($(this));console.log("cerrado click");

Open in new window

joyacv2Author Commented:
Hi Tom,

The code disappear the button guardar, my problem is that after i click the button guardar, i can't click the td again. Initially my code works well. I use the counter for create a unique class for each button guardar, i don't know if is completely necessary. After i press the guardar button, i need to have the ability to click again and do the same thing.
Tom BeckCommented:
I have no idea what you have on the page. You only posted the javascript. Have a look at my test.
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

joyacv2Author Commented:
sorry tom,

my html code looks like this

<html><body><table><tr><td class="cerrado">test<td></tr></table></body></html>
Tom BeckCommented:
I updated my jsfiddle to reflect this new information.

Do I have the solution?
joyacv2Author Commented:

when i press guardar the text that i enter in the input goes back to cerrado. The guardar button is a save button
Tom BeckCommented:
Updated to change the <td> text to whatever the user types in.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
joyacv2Author Commented:
Perfect Tom! Thank You!
Tom BeckCommented:
Another version with multiple rows and testing code removed.

You're welcome. Thanks for the points.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.