Skip to content

Instantly share code, notes, and snippets.

@tabebqena
Last active May 30, 2018 09:18
Show Gist options
  • Select an option

  • Save tabebqena/3843e052d64790e413c3ba9b795f0d2d to your computer and use it in GitHub Desktop.

Select an option

Save tabebqena/3843e052d64790e413c3ba9b795f0d2d to your computer and use it in GitHub Desktop.
function removeElement(id){
document.getElementById(id).parentNode.removeChild(document.getElementById(id));
}
function clearElement(element){
try{
console.info("function: clearElement.\nArguments: "+element)
var element = document.getElementById(element);
while (element.firstChild){
element.removeChild(element.firstChild);
};
}
catch(err) {
console.error(err.name , err.message);
}
}
function getFocus(id){
try{
console.info("function: getFocus.\nArguments: "+id)
document.getElementById(id).focus();
}
catch(err) {
console.error(err.name , err.message);
}
}
function scrollTo(eleID) {
try{
var e = document.getElementById(eleID);
if (!!e && e.scrollIntoView) {
e.scrollIntoView(true);
}
}catch(err){
console.error(err.name, err.message)
}
}
function highlight(id, color ='#f00', timeout=5000 ) {
try{
console.info("function: highlight.\nArguments: "+ id+ " "+ color + " " + timeout)
var timeout = timeout;
var el = document.getElementById(id);
//var org = el.style.borderColor;
//el.style.borderColor = color + " !imprtant";
el.classList.add("w3-red")
window.setTimeout( function(){
//el.style.borderColor = org;
el.classList.remove("w3-red")
} ,timeout);
}
catch(err) {
console.error(err.name , err.message);
}
}
function hideElement(id){
try{
console.info("function: hideElement.\nArguments: "+id)
document.getElementById(id).style.visibility="hidden";
}
catch(err) {
console.error(err.name , err.message);
}
}
function showElement(id){
try{
console.info("function: showElements.\nArguments: "+id)
document.getElementById(id).style.visibility="visible";
}
catch(err) {
console.error(err.name , err.message);
}
}
function enableElement(id){
try{
console.info("function: enbleElements.\nArguments: "+id)
document.getElementById(id).removeAttribute("disabled")
}
catch(err) {
console.error(err.name , err.message);
}
}
function disableElement(id, value="disabled"){
try{
console.info("function: disableElement.\nArguments: "+id)
document.getElementById(id).setAttribute("disabled", value)
}
catch(err) {
console.error(err.name , err.message);
}
}
function disableElements(List){
try{
console.info("function: disableElements.\nArguments: "+List)
for (var x=0; x<List.length; x++){
disableElement(List[x])
}
}
catch(err) {
console.error(err.name , err.message);
}
}
function enableElements(List_){
try{
console.info("function: enableElements.\nArguments: "+List_)
for (var x=0; x<List_.length; x++){
enableElement(List_[x])
}
}
catch(err) {
console.error(err.name , err.message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment