Javascript select nested class element

前端 未结 6 1152
遇见更好的自我
遇见更好的自我 2020-12-31 03:25

I\'m working on changing some elements the slider on my website

my slider code looks like this:

Some heading&

6条回答
  •  一生所求
    2020-12-31 03:55

    Edit: this is wrong as it doesn't take into account that two class names are given.

    I would suggest using JQuery for something like this, which will make it easier when you try to do something more complex. However the actual problem here is that getElementsByClassName returns an HTMLCollection of elements, and setting innerHTML on it doesn't set it on its elements. The following code should work:

    var elements = document.getElementsByClassName('cl1 sl_price');
    for (var i = 0; i < elements.length; i++) {
        elements[i].innerHTML = "from only £00.00
    "; }

提交回复
热议问题