Click here to Skip to main content
15,905,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my .html file, I defined the 2 objects as below:
HTML
<div id="selectedListTable" class='styleTable2' style="height:220px;width:565px;" />
<div id="loader_" class='loader' style='display:none;' />

In the js code, I got v but v2 as null
JavaScript
var v = document.getElementById("selectedListTable");
var v2 = document.getElementById("loader_");     // v2 is null

I don't know why? Appreciate if you can point out the reason.

What I have tried:

Got null for one of the objects
Posted
Updated 19-Apr-19 6:11am
Comments
[no name] 19-Apr-19 8:50am    
Try changing the style: you're saying the element is "invisible".
s yu 19-Apr-19 10:35am    
Did project cleaning & re-build. The problem was then gone. Thanks.
Bryian Tan 19-Apr-19 11:26am    
Is tough to tell by looking at 4 lines. It could be the structure of the markup, the location the v2 is being called, etc...
F-ES Sitecore 19-Apr-19 11:47am    
Make sure your js is running after the elements have been defined, ie the script element is below the div on the page.

1 solution

Your HTML is a bit of a mess:
HTML
<div id="selectedListTable" class='styleTable2' style="height:220px;width:565px;"/>
<div id="loader_" class='loader' style='display:none;' />
is obsolete and likely invalid - and don't seem to have any content. Unless the target of a later operation, they seem rather pointless, except to take up space.
HTML
<div id="selectedListTable" class='styleTable2' style="height:220px;width:565px;"></div>
<div id="loader_" class='loader' style='display:none;'></div>
is how they should look - with content between the opening and closing elements

If, perchance, your browser has trouble interpreting this then it may not have the two id='' attributes distinct. The closing of an element with '/>' is no longer "acceptable" - although may not through an error, depending upon the element. For example, and <img src=""> simply closes without the backslash. This is also true for <input> elements whilst something like a <div>> requires a closing </div>>

Assuming it isn't based on a problem elsewhere on your page, swap the two data request and see if you v2 and v is now null.
 
Share this answer
 
v2
Comments
s yu 19-Apr-19 13:18pm    
You are right. I revised the code like you pointed out and then the problem was gone. Thanks.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900