I am having trouble getting the link to be ‘(show)’ or ‘(hide)’ when I click on the link to either hide or show the paragraph text.
Here’s the code I got that won’t work:
var old_text = $(this).text();
var new_text = (old_text === '(hide)') ? '(show)' : '(hide)';
var toggle_link = $("<a href='#'> "+ new_text + "</a>");
$(this).after(toggle_link);
toggle_link.on('click', function (event){
$(this).siblings('p').toggle();
});
$(this).after(toggle_link);
In the above code. I am toggling the show and hide link on and off, however the text isn’t changing. It just remains (‘hide’).
Try this way: