This example shows how to use API for getting and setting the Redactor's code.
<!-- api buttons -->
<button onclick="console.log($R('#content', 'source.getCode'));">Get</button>
<button onclick="$R('#content', 'source.setCode', '<p>...</p>');">Set</button>
<!-- element -->
<textarea id="content"></textarea>
<!-- call -->
<script>
$R('#content');
</script>