Skip to content

How can i change the padding o element by class name

im trying to change the padding of all the td in table. somehow it doesnt work. can you help ?

script ->

enter image description here

css ->

enter image description here

html ->

enter image description here

Answer

As Martin said in the comments ID’s are unique selectors, so for apply style for td tag in script, you can use some thing like this:

<script>
  let td = document.getElementsByTagName('td');
  for (i = 0; i < td.length; i++) {
  td[i].style.padding = "20px";
  }
</script>

or change Id to class: strHtml += '<td class="curr-cell">'

and use document.getElementsByClassName('curr-cell') in above code.