ckeditor5
ckeditor5 copied to clipboard
How to get all img elements?
📝 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.
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.