0

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/

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Hawkeye Python
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);
         
    });
});
0

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

<a id="button1">- Table</a>

Instead of

- Table

But thanks anyway!

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.