I am trying to adapt this script: jQuery Example: Inserting text with drag n’ drop.
The goal is for my users to click an image thumbnail and have the appropriate markdown image code inserted into the textarea.
I am not familiar with JS, so I am aware that the meat of the script is happening here:
$('#ClickWordList li').click(function() {
$("#txtMessage").insertAtCaret($(this).text());
return false
});
specifically, the .text() bit there, but do not know how to alter the output to suit my needs for a snippet of markdown being inserted rather than just, say, the list text.
Markdown inline image syntax looks like this: 
I tried changing the list to a div with images and then changing to .insertAtCaret($(this).src); but I get “undefined” as the insertion text.
$(this).srcis undefined because$(this)is ajQuery object, and jQuery objects don’t have asrcproperty. Assuming you have an image element in your selector, You can try:The
.attr()jQuery method, when given only one parameter, will return the matched element’s given attribute’s value.or
To get the literal DOM element’s
src.Extra explanations (if you need)
The
.text()jQuery method, when given no parameters, will return all text inside of the element referenced bythis, that is, the event’s target, in this case the clickedliinside the#ClickWordListelement..insertAtCaret()is an extended function of the jQuery object provided by yourdrag 'n dropplugin.return falsewill do exactly what it says, returningfalsein theclickevent’s handler for the selected element, which simply cancels the event and prevents its propagation from bubbling up the DOM further.Sorry if there are any typos.