Skip to content

Instantly share code, notes, and snippets.

@nixon1333
Last active February 3, 2018 18:04
Show Gist options
  • Save nixon1333/2c5756784e173ce396bd34e634bff26f to your computer and use it in GitHub Desktop.
Save nixon1333/2c5756784e173ce396bd34e634bff26f to your computer and use it in GitHub Desktop.
// similar behavior as an HTTP redirect
window.location.replace("http://sidanmor.com");
// similar behavior as clicking on a link
window.location.href = "http://sidanmor.com";
//get value of a input item(of a id) using raw js
document.getElementById('inputID').value;
//get value of a input item(of a name) using raw js
document.getElementsByName('inputID')[0].value;
//===============
//get an element by class
function getElementsByAttributeValue(atrName,atrValue) {
var matchElems = [];
var allElems = document.getElementsByTagName('*');
for(var x = 0, len = allElems.length; x < len; x++) {
if(allElems[x].getAttribute(atrName) != atrValue) {
continue;
}
matchElems.push(allElems[x]);
}
return matchElems;
}
var elems = getElementsByAttributeValue("class","someclass");
//===============
//===============
//ajax request
$.ajax({
method: "<METHOD NAME>",
url: "some.php",
data: { name: "John", location: "Boston" }
})
.done(function( msg ) {
alert( "Data Saved: " + msg );
});
//===============
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment