Skip to content

Instantly share code, notes, and snippets.

@midu
Created February 9, 2011 17:54
Show Gist options
  • Save midu/818892 to your computer and use it in GitHub Desktop.
Save midu/818892 to your computer and use it in GitHub Desktop.
<script type="text/javascript">
var insertAtCursor = function (myField, myValue) {
//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
}
//MOZILLA/NETSCAPE support
else if (myField.selectionStart || myField.selectionStart == '0') {
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos)
+ myValue
+ myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
};
$(function () {
$('#images a').click(function (e) {
e.preventDefault();
insertAtCursor($('#midu')[0], $('<p><img src='+$(this).attr('href')+'/></p>').html());
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment