Skip to content

Instantly share code, notes, and snippets.

@Davis-Desormeaux
Created April 22, 2012 00:41
Show Gist options
  • Save Davis-Desormeaux/2440544 to your computer and use it in GitHub Desktop.
Save Davis-Desormeaux/2440544 to your computer and use it in GitHub Desktop.
Quick Dom Selector
function domSelect(element) {
var elm_type = element.substring(0, 1);
var _element = element.substring(1);
return elm_type != '.'
? elm_type != '#'
? document.getElementsByName(element) // Default to name.
: document.getElementById(_element) // By an id request.
: document.getElementsByClassName(_element) // By class request.
}
// Example:
alert(domSelect('#SomeIdValue').src) // Could be an image src
alert(domSelect('.SomeClassValue')[0].value) // 1st Element Found By Class
alert(domSelect('SomeTagValue')[0].value) // 1st Element Found By Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment