Get all Ids of all elements in document (edit)
var allElements = document.getElementsByTagName("*");
var allIds = [];
for (var i = 0, n = allElements.length; i < n; ++i) {
var el = allElements[i];
if (el.id) { allIds.push(el.id); }
}
var s=''; for(var i=0;i<allIds.length;i++) { s = s + allIds[i] + ';'; } alert(s);
console.log(document.querySelectorAll('*[id]:not([id=""])'));
var IDs = [];
$("#mydiv").find("span").each(function(){ IDs.push(this.id); });
Class name
<!-- HTML --> <a class="test" name="Name 1"></a> <a class="test" name="Name 2"></a> <a class="test" name="Name 3"></a> // Javascript var elements = document.getElementsByClassName("test"); var names = ''; for(var i=0; i<elements.length; i++) { names += elements[i].name; } alert(names);
Toggle class
$('#article-switch').click(function () {
$('article').toggleClass('newClass');
});
Properties of object
https://stackoverflow.com/questions/208016/how-to-list-the-properties-of-a-javascript-object
var keys = Object.keys(myObject);
var getKeys = function(obj){ var keys = []; for(var key in obj){ keys.push(key); } return keys; }
Pure Javascript
https://www.digitalocean.com/community/tutorials/how-to-access-elements-in-the-dom
https://flaviocopes.com/how-to-list-object-methods-javascript/
http://xahlee.info/js/js_get_elements.html
Element's ID that Start with
$(document).ready(function(){
$('input[id*=Name]' ).each(function(el){
el.val('Foo'); // do something with the input here.
});
});