Toggle navigation
MeasureThat.net
Create a benchmark
Tools
Feedback
FAQ
Register
Log In
textContent, innerText, innerHTML, nodeValue get value perf
(version: 0)
Comparing performance of:
textContent vs innerText vs innerHTML vs nodeValue
Created:
4 years ago
by:
Guest
Jump to the latest result
Script Preparation code:
var a = document.createElement('a'); a.innerText = 'text';
Tests:
textContent
a.textContent
innerText
a.innerText
innerHTML
a.innerHTML
nodeValue
a.nodeValue
Rendered benchmark preparation results:
Suite status:
<idle, ready to run>
Run tests (4)
Previous results
Fork
Test case name
Result
textContent
innerText
innerHTML
nodeValue
Fastest:
N/A
Slowest:
N/A
Latest run results:
No previous run results
This benchmark does not have any results yet. Be the first one
to run it!
Autogenerated LLM Summary
(model
llama3.2:3b
, generated one year ago):
Let's break down the provided benchmark JSON and explain what's being tested, compared, and the pros/cons of each approach. **Benchmark Definition** The test measures the performance (in executions per second) of getting the value of different properties on an HTML element: `textContent`, `innerText`, `innerHTML`, and `nodeValue`. The `Script Preparation Code` sets up a new HTML element (`a`) with the text "text". **Test Cases** Each test case represents one of the four properties being measured: 1. **textContent**: The text content of the element. 2. **innerText**: The inner text of the element, which excludes any surrounding whitespace or tags. 3. **innerHTML**: The HTML content of the element, including tags and attributes. 4. **nodeValue**: A non-standard property that returns the string value of an element's node. **Comparison** The benchmark compares the performance of accessing these four properties on a single element (`a`). **Pros and Cons of Each Approach** 1. **textContent**: * Pros: Fast, as it only needs to access the text content. * Cons: May not be supported by older browsers or in certain cases (e.g., if the element has no text). 2. **innerText**: * Pros: Faster than `innerHTML`, as it excludes surrounding whitespace and tags. * Cons: May not work in all cases, especially with complex elements or those containing non-ASCII characters. 3. **innerHTML**: * Pros: Returns the full HTML content of the element, which can be useful for parsing or manipulating HTML. * Cons: Slower than `textContent` and `innerText`, as it needs to parse and evaluate the HTML content. 4. **nodeValue**: * Pros: A non-standard property that provides a string representation of an element's node value. * Cons: May not be supported by older browsers or in certain cases (e.g., if the element has no text). **Libraries and Special JavaScript Features** None of these properties rely on specific libraries or features. They are all standard JavaScript properties that work across most modern browsers. **Alternatives** If you need to benchmark different approaches for accessing HTML element values, consider testing: * `outerHTML` (returns the entire HTML content of the element) * `text`: ( returns the text content of an element's child nodes) Keep in mind that these alternatives may have different performance characteristics and use cases compared to the properties measured in this benchmark. In summary, this benchmark measures the performance of accessing four different properties on a single HTML element. The results provide insight into which approach is fastest for common web development tasks.
Related benchmarks:
createTextNode, textContent, innerText, innerHTML, nodeValue
Get textContent, innerText, innerHTML, nodeValue
createTextNode, textContent, innerContent, innerText, innerHTML, nodeValue
textContent, nodeValue set value perf
Comments
Confirm delete:
Do you really want to delete benchmark?