Trying to write a basic jQuery plugin:
HTML:
<textarea>
    <p>Hello World!</p>
</textarea>
jQuery:
$.fn.wysiwyg = function (options) {
    var e = $(this).replaceWith("<iframe>");
    console.log($(this)[0].contentDocument);
};
$("textarea").wysiwyg();
JSFIDDLE DEMONSTRATION
The Problem
var e = $(this).replaceWith("<iframe>");
console.log($(this)[0].contentDocument);
I am getting undefined at the console. If I set an id attribute to this iframe and target that id in console.log method, it works perfectly, but I want to use $(this). What can be done for this?