Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок0
What's wrong with my code?
HTML code <table border="solid" id="A"> <tr><th>Int1</th><th>Int2</th><th>Int3</th></tr> <tr><td>1</td><td>2</td><td>3</td></tr> </table> JS code let a=document.getElementById("A"); let b=a.elements.Int2.value console.log(b) <!--It says elements is an error in the code. (This was from Introduction to JavaScript, Unit 3, lesson 2, known as Advanced User Input)-->
10 ответов
+ 1
Kongpheng Lo it works, just put the code between the script tag.
<script>
let table = document.getElementById("A");
let cellValue = table.rows[1].cells[1].textContent; // Access the second cell in the second row
console.log(cellValue);
</script>
+ 1
How are you running your code? Are you using the code playground?
0
I copied the text into my JavaScript code (I did not include the "Try this:" part in the code) and it says rows is the error in the code.
0
How come it works in script, but not in JavaScript?
0
That is how you use Javscript internaly in your HTML document.
0
I know, but why does it not work externally?
0
Ok, I'll recheck the lesson that talks about internal and external JavaScript.
0
I am still confused, but I now know that inline and internal JS code is in the .html file, while external JS code is in the .js file. I didn't think about files. Can I get some explain of how it being in a .js or .html file is different? I should understand why and it could help a lot.
0
Yea. Btw, I forgot to tell you guys that I'm only on introduction on JavaScript currently.
0
I just finished Introduction to JavaScript :p