0

I want to add text just with css. But pseudo-elements are not option. Point is to add text just with css, and have text in DOM.

Is that posssible ?

So this is not option :

.someClass:before {
  content: "some text";
}
14
  • 9
    NO if it's not with pseudo-elements....Why are those not an option? Commented Dec 23, 2014 at 14:49
  • I can't manipulate with JavaScript. I want later change that text on some click event. Commented Dec 23, 2014 at 14:54
  • 2
    CSS styles HTML...it's not intended to ADD it. Commented Dec 23, 2014 at 14:55
  • 1
    You can't use psuedo elements and you can't use javascript? you probably cant do what you want to do. Commented Dec 23, 2014 at 14:55
  • 1
    Why on earth wouldn't you be able to use pseudo elements, but would be open to any other css alternative? Commented Dec 23, 2014 at 15:16

2 Answers 2

5

In general, the entire purpose of CSS is to preserve the distinction between style/design and content. The pseudo-selectors are a little unique in that they don't select actually existing content to "style" it, but rather create the content in the first place.

This doesn't exactly interfere with the purpose of CSS because the distinction between content and design can sometimes get a little fuzzy. Cf., for example, http://css-tricks.com/css-content/ which talks of how appending "E-mail: " before every email address can actually be a style decision.

That said, I really don't understand why you don't want to use pseudo-elements. Support is near ubiquitous (http://css-tricks.com/browser-support-pseudo-elements/). Your only other option would be to use JS/jQuery or good ol' HTML.

Sign up to request clarification or add additional context in comments.

2 Comments

You can't select pseudo elements in jQuery because they are NOT part of DOM. I want set default values for class "someClass", but after that I want change some elemntsts with Jquery.
stackoverflow.com/questions/5041494/… gives you some options using jQuery. If you are looking for an effect on an event, for example, you can just use the jQuery addClass() function and use CSS to specify the appropriate content.
1

Cascading Style Sheets (CSS) is a simple mechanism for adding style (e.g., fonts, colors, spacing) to Web documents. (w3org)

You can not add any content without the use of :before or :after

In order to edit the DOM consider using jQuery or any other js script:

jQuery:

$('body').append('<div>Your new content</div>');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.