Greetings there are such a diva

<div class="field field-name-field-season field-type-list-text field-label-inline clearfix"> <div class="field-label">Сезонность:&nbsp;</div> <div class="field-items"> <div class="field-item even">Весь год</div> </div> </div> 

at

 <div class="field-label">Сезонность:&nbsp;</div> 

spelled out styles

  background: rgba(0, 0, 0, 0) url("images/vseses.png") no-repeat scroll 100% 100% / contain ; 

I would like to

1) add after loading the page to

 <div class="field field-name-field-season field-type-list-text field-label-inline clearfix"> 

title for description

2) depending on the text in

 <div class="field-item even">Весь год</div> 

change picture at diva

 <div class="field-label">Сезонность:&nbsp;</div> 

the easiest option is via the onload function attached to the body, but knowledge is slightly lacking

added script but console swears

 <script> window.onload=function chngsz(){ document.getElementsByClass(".field .field-name-field-season .field-type-list-text .field-label-inline .clearfix").setAttribute("title", "Item Added"); }; </script> 

The whole div looks like this

 <div class="group-spec field-group-div"> <div class="field field-name-field-season field-type-list-text field-label-inline clearfix"> <div class="field-label">Сезонность:&nbsp;</div> <div class="field-items"> <div class="field-item even">Весь год</div> </div> </div> <div class="field field-name-field-weight field-type-number-integer field-label-inline clearfix"> <div class="field-label">Вес:&nbsp;</div> <div class="field-items"> <div class="field-item even">66 кг</div> </div> </div> <div class="field field-name-field-length field-type-number-integer field-label-inline clearfix"> <div class="field-label">Длина:&nbsp;</div> <div class="field-items"> <div class="field-item even">3 100 см.</div> </div> </div> <div class="field field-name-field-shirina field-type-number-integer field-label-inline clearfix"> <div class="field-label">Ширина:&nbsp;</div> <div class="field-items"> <div class="field-item even">1 200 см.</div> </div> </div> <div class="field field-name-field-visota field-type-number-integer field-label-inline clearfix"> <div class="field-label">Высота :&nbsp;</div> <div class="field-items"> <div class="field-item even">1 200 см.</div> </div> </div> <div class="field field-name-field-crew field-type-range-integer field-label-inline clearfix"> <div class="field-label">Экипаж:&nbsp;</div> <div class="field-items"> <div class="field-item even">12&ndash;15 чел.</div> </div> </div> </div> 

    1 answer 1

    Good morning. It is possible so:

    js:

     window.onload = function() { var elemForTitle = document.getElementsByClassName("field-name-field-season"); var elemForImageChange = document.getElementsByClassName("field-item"); elemForTitle[0].className += " title"; for(el in elemForImageChange){ if(elemForImageChange.hasOwnProperty(el)){ switch(elemForImageChange[el].innerHTML) case 'Весь год': elemForImageChange[el].style.background = 'стили для фона'; break; ... ... } } }; 

    It is possible to hang classes in a switch, and not to affix styles. But in my opinion it is better to do all this, at the moment when you create these fields (.field), otherwise double work is obtained.

    • there drupal. I can’t add something (((if I could - I’d tie the ID to the divas and that's it. and so I’m suffering (((Thank you! Right now for the test! - Igor Fostiaq
    • chngsz is not defined <body class = "<? php print $ classes;?>" <? php print $ attributes;?> onload = "chngsz ()"> - Igor Fostyak
    • This is probably the function you are trying to declare so window.onload=function chngsz(){ ? Use an anonymous function, as in my example. Or correctly define the function chngsz(){...}; window.onload = function(){chngsz();} function: function chngsz(){...}; window.onload = function(){chngsz();} function chngsz(){...}; window.onload = function(){chngsz();} - Mikl
    • @Miki A little bit wrong (the field-item should check the text, but change the background of the field label. And title = "title" does not add a field-name-field-season to the div (a hint to be seen by the diva) - Igor Fostyak
    • It did not work out that way. I adjusted the title elemForTitleS1 [0] .title + = "Product weight"; but it only changes the field item image, not the field label. - Igor Fostyak