my question is that I am using jQuery in JavaScript and using detach and append. Here is my JavaScript append and detach script.
var example1 = $(".example1").detach();
var example2 = $(".example2").detach();
showexample2();
$("#blue").click(function(){
    alert("hi");
    showexamples2();
    hideexamples1();
});
$("#red").click(function(){
    hideexamples2();
    showexamples1();
});
function hideexamples2(){
    $(".example2").detach();
}
function showexample2s(){
    $("body").append(example2);
}
function hideexamples1s(){
    $(".example1").detach();
}
function shoexamples1s(){
    $('body').append(example1);
}
However when red is clicked it ends up below the JavaScript and therefore has no functionality.

How can I fix this?
 
     
    