Javascript select nested class element

getElementsByClassName returns a collection (list) of elements
(will therefore not have a innerHTML property)

You could try document.querySelector(".cl1 .sl_price") instead (takes a css selector and returns the first match)

read more at https://developer.mozilla.org/en-US/docs/Web/API/Document.querySelector

The end result would then be something like this;

document.querySelector('.cl1 .sl_price').innerHTML = "from only £00.00<br>";

Note: I am assuming you only wanted to match a single element. If not, you should look at @Bommox’s answer and querySelectorAll.

Leave a Comment