Ask coding questions

← Back to all posts
Javascript question! plz help.

I am trying to add checked="checked" to which ever input is nested inside inside a div class name of slide-active but for some reason my javascript code below isnt working. Any help would truly be appreciated. Thanks.


When you call document.getElementsByClassName() that is returning an array of elements, but when you use the result, you're treating it like a single element (classList is defined on an element, not on an array of elements). You'll need to go through the array and check each element in it until you find the one you're looking for.

Once you've found the right div, you'll need to find a way to get the input from inside it. Be careful, though, if you use something like getElementsByTagName("input") even though there's only one input inside each div, you'll still get an array (with one element in it).

I hope that helps!