Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/oslego/data-text-content

Small JavaScript component to clone an element's text content to a data attribute on itself.
https://github.com/oslego/data-text-content

Last synced: about 1 month ago
JSON representation

Small JavaScript component to clone an element's text content to a data attribute on itself.

Awesome Lists containing this project

README

        

# data-text-content

JavaScript component to clone an HTML element's text content to a data attribute called `data-text-content`. Keep in sync automatically.

For use in CSS as content for pseduo-elements with `content: attr(data-text-content)`.

## Example

```html

/* create reflection effect */
p::after{
content: attr(data-text-content);
transform: rotateX(180deg);
display: block;
}

Reflect this

```

## Usage

1. Load the JavaScript component
```html

```
2. Set the `data-text-content` attribute on target elements
```html

Reflect this


```

The target elements will have their `data-text-content` attribute automatically updated and synchronized with the element's text content.

In CSS, you can reference the `data-text-content` attribute and use its value. For example, as content for pseduo-elements:

```css
p::after{
content: attr(data-text-content);
}
```