I want to get all classes of the HTML element on my page, split it and store it in array. After that I want to write it into my table in the div with the id \"table\" which
It is not clear if you want the class names per row or per column. These examples are one class name per row. Try this:
var elm = $('#test'),
table = $('').appendTo(elm);
$(document.documentElement.className.split(' ').each(function() {
table.append(''+this+' ');
});
I used native code to get the classNames of the HTML element: document.documentElement.className, but you might as well use $('html').attr('class').
A native JS example using innerHTML:
var d = window.document,
elm = d.getElementById('test'),
html = '',
classes = d.documentElement.classNames.split(' '),
i = 0;
for(; classes[i]; i++) {
html += '' + classes[i] + ' ';
}
elm.innerHTML = html + '
;
- 热议问题