Tuesday, December 6, 2016

JavaScript - jQuery - DOM Manipulation - Q&A

Question:

Output all elements count and print them to the page in the following format :








Answer

var all = $('*');
console.log( all.length );
var elements = [];
for (var i = 0;  i < all.length;  i++){
    if (!elements[$(all[i]).prop('tagName')])
        elements[$(all[i]).prop('tagName')] = 1;
    else
        elements[$(all[i]).prop('tagName')]++;
};
console.log(elements);

2 comments:

  1. allintext:"DOM JavaScript" "powered by blogger"
    JavaScript is the language future. The new JavaScript Version (Ecmascript 6) has been relaeased.

    JavaScript Online Training

    Javascript Online Training

    ReplyDelete