Javascript select nested class element

前端 未结 6 1191
遇见更好的自我
遇见更好的自我 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

    I believe what you need to do is something like this:

    document.getElementsByClassName('cl1').getElementsByClassName('sl_price')[0].innerHTML="from only £00.00
    ";

    The way you're doing it right now will get elements that have both the classes cl1 and sl_price. If you chain your methods, you'll be telling it to look for elements with cl1 as a class inside the document object, return an object with that subset, then look inside that subset for elements with the sl_price class. You then have to specify an index because document.getElementsByClassName will return an array of elements matching your requirements. That array will not have a property array.innerHTML, but the objects contained in its indexes will.

提交回复
热议问题