Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Line breaks are ignored by innerText #249

Closed
1RandomDev opened this issue Sep 5, 2023 · 6 comments
Closed

Line breaks are ignored by innerText #249

1RandomDev opened this issue Sep 5, 2023 · 6 comments

Comments

@1RandomDev
Copy link

1RandomDev commented Sep 5, 2023

When using the innerText function on elements that contain line breaks (<br>) they get ignored in the output. A regular browser will convert them to \n characters.
For exmple Hello<br>World will result in HelloWorld, but expected is Hello\nWorld.

@zyrouge
Copy link

zyrouge commented Sep 7, 2023

+1

@taoqf
Copy link
Owner

taoqf commented Sep 8, 2023

I am afraid I cannot see this behavior in chrome. my test code is like this

const div = document.createElement('div');
div.innerHTML = 'Hello, <br>World!';
console.log(div.innerText);

@taoqf taoqf closed this as completed Sep 8, 2023
taoqf added a commit that referenced this issue Sep 8, 2023
@taoqf
Copy link
Owner

taoqf commented Sep 8, 2023

I add a new branch for this issue, but I don't think we should merge this, because chrome does the same.

@1RandomDev
Copy link
Author

I am afraid I cannot see this behavior in chrome. my test code is like this

const div = document.createElement('div');
div.innerHTML = 'Hello, <br>World!';
console.log(div.innerText);

Appears that it only works if the element is added to the DOM. Like this it's working fine.

const div = document.createElement('div');
document.body.appendChild(div);
div.innerHTML = 'Hello, <br>World!';
console.log(div.innerText);

@taoqf taoqf added bug and removed wontfix labels Sep 11, 2023
@taoqf
Copy link
Owner

taoqf commented Sep 11, 2023

Merged.

@taoqf
Copy link
Owner

taoqf commented Sep 11, 2023

And thank you for feeding back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants