Skip to content

Instantly share code, notes, and snippets.

@rainyjune
Created February 13, 2013 06:01
Show Gist options
  • Save rainyjune/4942583 to your computer and use it in GitHub Desktop.
Save rainyjune/4942583 to your computer and use it in GitHub Desktop.
Get or set inner HTML/text content of a DOM element
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