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/

Recommended Answers

All 2 Replies

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);
         
    });
});

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

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

Instead of

- Table

But thanks anyway!

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.