im trying to change the padding of all the td in table. somehow it doesnt work. can you help ?
script ->
css ->
html ->
Advertisement
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:
JavaScript
x
7
1
<script>
2
let td = document.getElementsByTagName('td');
3
for (i = 0; i < td.length; i++) {
4
td[i].style.padding = "20px";
5
}
6
</script>
7
or change Id to class: strHtml += '<td class="curr-cell">'
and use document.getElementsByClassName('curr-cell')
in above code.