0

I'm trying to add top to class based on div height:

jQuery(document).ready(function($) {    
    var offsetHeight = $(test).height(); //Successfully Got height   
    var txt = "Height with padding and border: " + offsetHeight + "px";
    document.getElementsByClassName("logo_helper").style.top = txt;
});

And i get such error:

Uncaught TypeError: Cannot set property 'top' of undefined
at HTMLAnchorElement.<anonymous>

I'm not very strong at JS. Can someone help?

Rost
  • 185
  • 1
  • 5
  • 19
  • document.getElementsByClassName("logo_helper")[?] – VXp May 22 '18 at 12:39
  • 1
    The the linked question's answers. `getElementsByClassName` returns a *list* of elements. To access elements in the list, you need to index into it (`[0]`, `[1]`, etc.) and then you can use `.style` on the elements. Alternately, add a new `style` element to `head` with a rule for the class so you don't have to handle each element individually. – T.J. Crowder May 22 '18 at 12:40

0 Answers0