1

If I write my new line character 
 directly as HTML attribute, then it can work for CSS generated content. For example:

div::after {
    content: attr(data-generated-content);
    white-space: pre;
    }
<div data-generated-content="First line&#xa;Second line"></div>

However, if the new line character was added via jQuery, then it doesn't work. For example:

$(document).ready(function() {
	$('div').attr('data-generated-content', 'First line&#xa;Second line');
});
div::after {
    content: attr(data-generated-content);
    white-space: pre;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<div></div>

Here is a complete demo on jsFiddle.

How do I make the new line character added via jQuery work for CSS generated content?

1 Answer 1

2

Use javascript \n instead, here is a demo:

$(document).ready(function() {
	$('div').attr('data-generated-content', 'First line\nSecond line');
});
div::after {
    content: attr(data-generated-content);
    white-space: pre;
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<div></div>

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

1 Comment

@IanY. i'm glad i could help

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.