I have the code which gets the currently selected image, but I would like to get the first image in contents if one has not already been selected. Im using the code below which has been adapted from original which returned an href.
var range = selection.getRanges(true)[0];
range.shrink(CKEDITOR.SHRINK_TEXT);
var root = range.getCommonAncestor();
return root.getAscendant('img', true);
How could I get the first image which appears in the contents?
As I can understand you need DOM node instead the CKEditor node, right? If so
getAscendant('img', true)returnsCKEDITOR.dom.nodeso you can get native DOM node from$object.Or then use the
img.getAttribute( 'src' )