Welcome to the Kung Fu Garden

Explore various micro projects and platforms by x51 and friends.

@kung-fu/components v0.4.0


@kung-fu/components / wrapImageWithFigure

Function: wrapImageWithFigure()

wrapImageWithFigure(selector?, exclusion?): void

Wraps images with figure and figcaption elements. Uses the image's title or alt text as the figcaption content. Skips images that have the specified exclusion attribute.

Parameters

selector?

string

CSS selector for images to wrap (defaults to 'img')

exclusion?

string

Attribute that marks images to skip (defaults to 'data-no-caption')

Returns

void

Examples

// Wrap all images on the page with figure elements
wrapImageWithFigure();
// Wrap only images with a specific class
wrapImageWithFigure('.article-image');
// Use a custom attribute to mark images that should not be wrapped
wrapImageWithFigure('img', 'data-skip-figure');