Monday, February 26, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  186] [ 1]  / answers: 1 / hits: 5469  / 10 Years ago, tue, december 31, 2013, 12:00:00

I want to change this from jquery to javascript:
$('#id_of_element').children('div').addClass('some_class');



So far all i have is this(not working):

document.getElementById('id_of_element').getElementsByTagName('div').addClass('some_class');



I have to change all my code from jquery to javascript. Is there any site with have examples of functions in javascript next to jquery? Thanks in advance for all help :)


More From » jquery

 Answers
0

Try



var el = document.getElementById('elem'),
//modern browsers IE >= 10
classList = 'classList' in el;
for (var i = 0; i < el.children.length; i++) {
var child = el.children[i];
if (child.tagName == 'DIV') {
if (classList) {
child.classList.add('test');
} else {
child.className += ' test'
}
}
}


Demo: Fiddle


[#49112] Monday, December 30, 2013, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
yulisa

Total Points: 436
Total Questions: 102
Total Answers: 123

Location: Palau
Member since Tue, May 30, 2023
10 Months ago
;