0

I have a modal with content that if there is no result, it shows the option to search further. I have the button working, but it makes an AJAX call and that works well. What I am struggling with is what to do to show the new content. I have the JQUERY remove function working, but when I try to use SHOW to display the new content, I am not getting anything. Am I along thinking along the right line?

        success: function(data){
            jQuery('#test').remove(); 
            jQuery('#test2').show();
}
FSDford
  • 448
  • 5
  • 10
Kris
  • 77
  • 7
  • Not sure what `#test` is... But I already answered someting similar related to modal content filled by some ajax result. Check [this](https://stackoverflow.com/a/48388879/2159528). – Louys Patrice Bessette Dec 28 '20 at 23:12
  • Thanks so much. #test is a table id. I took a look - good post btw. It doesnt seem quite like what I am doing though since I am already keeping the modal. I already actually am loading the new data as a function of the callback from the initial AJAX. My issue is that it wont bring up the new data instead. Any ideas? :) – Kris Dec 29 '20 at 02:03

1 Answers1

0

If the element with id 'test2' is already in the modal structure at the same location as element with id 'test' then this should work.

If not, you'll need to put it there.

// get the parent of the existing element
var parentEl = $('#test').parent();
// remove existing element
$('#test').remove();
// detach the new element from wherever it is and append it below parent, and show it
$('#test2').detach().appendTo(parentEl).show();
Neil W
  • 7,670
  • 3
  • 28
  • 41
  • Thanks. The table with id Test2 is in a separate function actually but that function is the one that the AJAX data action is referencing if that makes sense? I presume with that knowledge I need to use the above ? Interestingly the #Test is actually in a different function all together. – Kris Dec 28 '20 at 23:12
  • So I have been playing with this - thanks for writing it up. I Am not able to get it to work though. It removes the previous message and button but doesnt bring anything else up. If there is no table left to append to, will it still add things to the modal? – Kris Dec 29 '20 at 01:54