getElementById results to null: Uncaught TypeError: Cannot read property 'getAttribute' of null

Asked 2 years ago, Updated 2 years ago, 55 views

Uncaught TypeError: Cannot read property 'getAttribute' of null
The error line is shown in the third line of this code.

Code

vara=param.getAttribute("a");
varb = document.getElementById(a);
varc_class = b.getAttribute("class");

I am using jquery.

I wonder what it is because only certain users have errors.
What does this mean?
Is it correct that the contents of the getAttribute function in the third line are null?

I modified the code a little, but it looks like this.

javascript jquery

2022-09-30 19:33

1 Answers

In the first line, getAttribute("a") is trying to retrieve the value of the "a" attribute, although it is unclear what param is.If param is an element, does the a attribute exist?
If it does not exist, it returns null, so it seems that there is no attribute itself.


2022-09-30 19:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.