I am trying to inject code into an iframe but I haven't had any luck and I'm not sure why. I store my js code into a variable, which works properly at this point, into a variable called pixel_code. I then want to inject that code into the iframe. Assuming the id of the iframe is "iframe_" how would I inject the code (variable is pixel_code) into the iframe and execute it? I think jquery would be the easiest way, but I'm open to regular JS as well.
One of my many unsuccessful attempts is:
function captureValue(){
pixel_code = document.getElementById("baseText").value;
$('#iframe_').find('body').append(pixel_code);
}
No errors are generated in the console.