954,566 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

JQuery replaceWith

Hi! I don't know much about Java and I'm new to JQuery.

I want to replace "+ Table" for "- Table" when the user clicks on it.

For that I've used:

$(document).ready(function () {
    $('#table1_head').click(function () {
	$('#button1 a').replaceWith('- Table1');
    });
});


It worked. But I want to replace "- Table" back for "+ Table" when the user clicks on it again. How can I do that?

Demo: http://www.teste442.xpg.com.br/example/

Hawkeye Python
Light Poster
34 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

maybe you can do this...

$(document).ready(function () {
  var x = '- Table1';

    $('#table1_head').click(function () {
        if(x == '- Table1') x = '+ Table1';
        else x = '- Table1';

	$('#button1 a').replaceWith(x);
         
    });
});
codewall
Junior Poster in Training
80 posts since Dec 2010
Reputation Points: 13
Solved Threads: 11
 

I've found the error
The entire line needs to be replaced...

- Table

Instead of

- Table

But thanks anyway!

Hawkeye Python
Light Poster
34 posts since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: