ckeditor5 icon indicating copy to clipboard operation
ckeditor5 copied to clipboard

How to get all img elements?

Open devgogo opened this issue 6 years ago • 1 comments

📝 Provide a description of the new feature

I want to get all the IMG elements, and their attributes. src, width, height,uploadStatus…. thx.

If you'd like to see this feature implemented, add a 👍 reaction to this post.

devgogo avatar Jun 08 '20 08:06 devgogo

Hi, if you want to get all image elements you can start with code like this:

const range = editor.model.createRangeIn( editor.model.document.getRoot() );

for ( const value of range.getWalker( { ignoreElementEnd: true } ) ) {
    if( value.item.is( 'element' ) && value.item.name === 'image' ){
        console.log( value.item );
    }
}

This creates a range containing all editor content, goes through it and logs only elements, that are images. You can then access the elements and its attributes.

FilipTokarski avatar Jun 09 '20 08:06 FilipTokarski