Created
February 13, 2013 06:01
-
-
Save rainyjune/4942583 to your computer and use it in GitHub Desktop.
Get or set inner HTML/text content of a DOM element
This file contains 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
function html(element, htmlContent) { | |
if(htmlContent === undefined) { | |
return element.innerHTML; | |
} else { | |
element.innerHTML = htmlContent; | |
} | |
} | |
function text(element, value) { | |
var content = element.textContent; | |
if (value === undefined) { | |
if (content !== undefined) return content; | |
else return element.innerText; | |
} else { | |
if (content !== undefined) element.textContent = value; | |
else element.innerText = value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment