skip to Main Content

Javascript – How to get the attribute of an innerHTML?

I'm trying to get the value of a span attribute (data-red) inside a table cell. <td class=" u-tL" headers="due-date" aria-labelledby="due-date"><span data-red="255" style="display: block; width: 75px;">19-JAN-2024</span></td> I've tried the code below but it's giving me the error "Uncaught TypeError: spn.getAttribute is…

VIEW QUESTION

Html – why json file value is not displayed (javascript)

<script> // Fetch JSON data fetch('dat.json') .then(response => response.json()) .then(data => { const tbody = document.querySelector('#dataTable tbody'); data.forEach(item => { const row = document.createElement('tr'); row.innerHTML = ` <td>${item.name}</td> <td>${item.age}</td> <td>${item.city}</td> `; tbody.appendChild(row); }); }) .catch(error =>console.error('Error fetching the data:', error));…

VIEW QUESTION
Back To Top
Search