V
V
vvrider2015-09-28 17:06:45
JavaScript
vvrider, 2015-09-28 17:06:45

How to copy information from div using .text js without losing formatting?

How to copy information from a div using .text js without losing formatting:

There is a div, it has headings, li (with a list of products), total amount and quantity (span)

Using the .text function, I copy the text to another block (to then transfer it to textarea in email form).

As a result, the data is copied, but I want to keep the original formatting (indents, etc.)

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Gregory, 2015-09-28
@vvrider

Use .html() instead of .text()
PS:

var newtext = $('div').text().replace(/<[^>]*>/g, "\n");
- © vvrider

A
Alexander Aksentiev, 2015-09-28
@Sanasol

text ignores tags, where does the formatting come from

A
Akim Glushkov, 2015-09-28
@mikaakim

Margins are created using css, and how can you get them using js with a single function? No way ... you need to parse them and look at what is on this element.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question