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

svg element innertText is undefined #1151

Closed
infeng opened this issue Oct 31, 2023 · 1 comment · Fixed by #1753
Closed

svg element innertText is undefined #1151

infeng opened this issue Oct 31, 2023 · 1 comment · Fixed by #1753
Labels
bug Something isn't working

Comments

@infeng
Copy link

infeng commented Oct 31, 2023

Describe the bug
svg element innertText is undefined, it should be a string.

To Reproduce

const { Window } = require('happy-dom');

const window = new Window({
	url: 'https://localhost:8080',
	width: 1024,
	height: 768
});

const div = window.document.createElement('div');
div.innerHTML = '<div><span><svg></svg></span>123<div>';
window.document.body.appendChild(div);
console.log(div.innerText);

actual log: undefined123

Expected behavior
expected log: 123

Device:

  • OS: mac
  • Browser: node
  • Version: 16.20.1
  • happy-dom version: 12.10.3

Additional context
in https://github.com/capricorn86/happy-dom/blob/master/packages/happy-dom/src/nodes/html-element/HTMLElement.ts#L101, I think the judgment here should be whether it's HTMLElement or not, only htmlelement has innerText

@infeng infeng added the bug Something isn't working label Oct 31, 2023
karpiuMG added a commit to karpiuMG/happy-dom that referenced this issue Feb 28, 2025
karpiuMG added a commit to karpiuMG/happy-dom that referenced this issue Feb 28, 2025
capricorn86 added a commit to karpiuMG/happy-dom that referenced this issue Mar 6, 2025
capricorn86 added a commit that referenced this issue Mar 6, 2025
* fix: [#1151] Skips svg elements when innerText is used

* fix: [#1151] Add newline if it's a block/flex element and there's more content coming after

* chore: [#1151] Improves performance and removes incorrect comment

---------

Co-authored-by: David Ortner <[email protected]>
@capricorn86
Copy link
Owner

Thank you for reporting @infeng! 🙂

Thanks to @karpiuMG there is a fix in now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants