Questions tagged [getelementbyid]
getElementById is an essential method commonly used in JavaScript in the browser to retrieve a particular element node in a HTML or XML document by its ID.
getelementbyid
2,433
questions
2
votes
1
answer
17
views
Mat-table get column width
How can I get column header width (angular mat-table) in typescript? I tried to use id and get elementById.clientWidth but it doesn't work for mat table column.
I need to get the size of each column ...
0
votes
1
answer
27
views
jest jsdom - dom.window.document.getElementById(X) succeeds but document.getElementById(X) fails
This one is a real head scratcher, neither Google nor ChatGPT could solve it.
This is a simple and straightforward jest test using jsdom, I've seen dozens like it in blogs and Github.
The 1000ms ...
0
votes
0
answers
22
views
Referencing DOM objects directly by their IDs is automatically enabled - is it a good practice? [duplicate]
I was today years old when I learned that every HTML element added to the DOM and given an id is automatically added to the window object using the name provided in the id.
For example, <input type=...
1
vote
4
answers
81
views
javascript program stops executing
I have a Package Class where a random ID is given at the beginning and a package type can be chosen afterwards.
It seems, that the values are given correctly. I can click between package and letter....
-1
votes
1
answer
59
views
How to change HTML Div content when button in clicked using Javascript?
I want to let the user click a button that will change the contents of the div. I'm creating a football lineup with each button representing a formation and when they click the button, the contents of ...
0
votes
0
answers
10
views
Issues when appending new element
I have an issue with this error code "Uncaught TypeError: Cannot read properties of undefined (reading 'append')"
In this case, the container I want to append the new P to, is undefined. ...
-1
votes
1
answer
51
views
From getElementById to getElementsByClassName and get same result?
Looking at the code below, you will notice when I click the arrow icons an "Added!" text will appear in green to the left, but in one spot only.
I want the "Added!" text to appear ...
0
votes
1
answer
33
views
Is there any reason to use document.getElementById instead of the ID itself? [duplicate]
For example, to remove an element from the DOM, myEl.remove() works just as well (in Firefox and Chrome) as document.getElementById("myEl").remove()
0
votes
0
answers
16
views
React - How can a DOM-Element that is passed by Parameter be manipulated?
So let's imagine the following scenario:
const ExampleComponent = ({categories, item}:{categories: string,item:JSX.Element|JSX.Element[]}) => {
return <div>
<div>{...
0
votes
2
answers
2k
views
Uncaught TypeError: Cannot read properties of null (reading 'value') getElementById
I'm getting this error when clicking on the button.
Uncaught TypeError: Cannot read properties of null (reading 'value')
What am I doing wrong? Here's the code:
<table>
<tr&...
0
votes
0
answers
59
views
Why querySelector show 2 different way of result in Edge console?
I have a div element by id "test", and here is my javascript code:
const test = document.querySelector("#test");
console.log(test);
Then I open the console of Edge, but the result ...
-1
votes
1
answer
36
views
js for loop innerHTML function does not work on load on same id
for loop innerHTML += does not work when function is called on addeventlistener load
<main id='outSecs'>
foobar
</main>
<script>
document.getElementById('outSecs')....
0
votes
1
answer
48
views
Let receive 0 but not invalid values
I have a input that i want to recive any number (dont matter if its negative, float, long) i code this to now allow null, undefined or empty values, but if I enter 0 it is read as empty
const ...
0
votes
0
answers
54
views
Only getElementById works with code...getElementbyClassName and document.querySelectorAll aren't working
The following code works when I use get ElementById, but won't work when I switch to querySelectorAll, querySelector, or getElementbyClassName.
The table ID is always BlockLayoutController and then a ...
0
votes
1
answer
59
views
Problem with javascript loop and setting documentGetElementById with parameters
I'm working on a star rating system. I want to set event listeners on a list of star images such that clicking on a star either fills in the stars with solid or blank stars. The problem is that when ...