Starkers
Starkers

Reputation: 10541

Is there an equivalent for the 'content' rule that works on elements?

I want to apply the content rule to an element that isn't a pseudo element:

css:

#element {
    content: 'foobs'
}

html:

<div id = '#element'></div>

I then wish to retrieve the computed style via javascript:

javascript:

console.log(window.getComputedStyle(document.body, '#element').content ) //=> 'foobs';

This works perfectly when using a pseudo element instead of #element, but I want to use a real element for compatibility reasons (IE7 +).

In short, an alternative to the content rule that works on true elements.

Upvotes: 2

Views: 56

Answers (1)

BoltClock
BoltClock

Reputation: 723688

There isn't one; the content property is only applicable to the ::before and ::after pseudo-elements. Especially if you're looking to set content on elements programmatically "for compatibility reasons" and ::before/::after is not available, you won't find such a solution with CSS. In such a case, you will have much better luck using JavaScript or a server-side solution than using CSS for a lot of other things, not just generated content.

Upvotes: 7

Related Questions