Copy text: cannot find my syntax error

Copy text: cannot find my syntax error

I want to conditionally copy the text to a popup, however if I use a var, it works; if I use the selector, it does not work.  In the example below, the var textVal works, but the selector,  "div#text1" does not work.  Probably been looking at it too long!

Todd

  1. $(document).ready(function(){

  2. $("li a").click(function() {
  3. var popupName = $(this).attr("id");
  4. var textVal = $("div#text1").html();
  5. //alert(popupName);
  6. //alert(textVal);

  7. if (popupName == "showPopup1") {
  8.   // This does work 
  9.   $(textVal).insertAfter("div#popupText").html();
  10.   // This does not work  
  11.   //$("div#text1").insertAfter("div#popupText").html();
  12. } else if (popupName == "showPopup2") {   
  13.   $("div#text2").insertAfter("div#popupText");    
  14. }
  15.     
  16. $("#middleLayer").toggle();
  17. $("#popup").toggle();
  18. });
  19. });