Created
September 19, 2016 19:04
-
-
Save barnes7td/79ea9e0495efd8a8f0b92e27ca027720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
<p id="test"> Hey <span>Text</span> </p> | |
... | |
var linkText = document.getElementById('test').textContent; Hey Text | |
var linkText = document.getElementById('test').innerText; Hey | |
var linkText = document.getElementById('test').childNodes[0].nodeValue; Hey | |
var linkText = document.getElementById('test').firstChild.nodeValue; Hey // Only works on Text nodes | |
console.log(linkText); | |
(p html element node) // childNodes [ TextNode, ElementNode(span) ] | |
| | | |
| +--> (Text node).nodeValue = "Hey" | |
| | |
+--> (span html element node).childNodes = [textnode, attributenodes, onandonnodes] | |
| //.childNodes[0] || .firstChild | |
+--> (Text node).nodeValue = "Text" | |
var text = document.getElementById('test').childNodes[1].childNodes[0].nodeValue; //=> "Text" | |
var linkText = document.getElementById('test').childNodes[0].nodeValue; | |
document.getElementById('test').innerText; | |
$('#test').val(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment