javascript Cannot read property 'children' of null whilte - javascript

I have this snippet code at codepen and it's working perfectl, but
When trying copy it to my site it's show this error :
(index):257 Uncaught TypeError: Cannot read property 'children' of null
at (index):257
(anonymous) # (index):257
which means this line in my site :
var count = items.children.length;
I just copy compiled html, css and js same it's without any edit, May I know why this happen ?

You probably have the Javascript code in your <head></head> tag.
There the DOM is — not — ready yet.
Try copying your <script>code</script> right before the </body> tag.

Related

Error can't redefine non-configurable property "userAgent"

Lately we have been getting a lot of javascript errors "can't redefine non-configurable property "userAgent"".
We don't attempt to redefine userAgent in our code. We barely even reference userAgent. The only places would be in code like the following:
var browser_msie = (navigator.userAgent.match(/msie/i) || navigator.userAgent.match(/trident/i)) ? true : false;
I am wondering if this error is rather coming from some bad browser behavior. It only started showing up recently.
Last evening we got over 20,000 of such error messages, and all from the same member of our service.
EDIT
The error information is as follows:
Error Message:
Message: TypeError: can&#39;t redefine non-configurable property &#34;userAgent&#34;
URL: https://www.rephunter.net/member-home.php
Line:1
Column:130
Stack:#https://www.rephunter.net/member-home.php:1:130
Error Traceback:
#0 Called backtrace in file /var/www/rephunter/www/webroot/include/error-handler-inc.php as line #68
#1 Called error_handler in file as line #
#2 Called trigger_error in file /var/www/rephunter/www/webroot/ajax/javascript-error.php as line #14
Unfortunately this offers no help, as line 1 of the page is just <!DOCTYPE html>. I don't see how to get to that part of the code. Of course if that were possible it might be easy to see the cause of the issue.
I recall in the past the Dev Tools might have given a "spiders view" of the page, but now I only see the DOM on the Elements tab, and Sources. Both of these are formatted and their is no way to see what "line 1 char 130" means.

Why am I getting "Cannot set property 'innerHTML' of null at ahint"

I have tried to write some code in JS but, when I hover my mouse, the error "Cannot set property 'innerHTML' of null at ahint" is seen. I have read that such an error can occur because Chrome compiles/renders the JS code before the Div is even created. Therefore, I have put it on the bottom to check it. Unfortunately, putting it on the bottom has not solved my problem. Maybe someone more experienced will understand it.
var hint = "Hello";
function ahint()
{
document.getElementById('#randomhint').innerHTML = hint;
}
<div id="randomhint" onmouseover="ahint()">!</div>
<script type="text/javascript" src="main.js"></script>
</body>
Remove the # from the identifier:
var hint = "Hello";
function ahint()
{
document.getElementById('randomhint').innerHTML = hint;
}
You have likely seen the # in code that uses jQuery or a similar library, as in $('#randomhint'). That’s how those libraries know that you mean to use an id and not, say, a tag name.
But you do not need (and cannot use) it when using getElementById (which is part of “vanilla” JavaScript). With getElementById, only the actual id value ("randomhint") belongs there.

python webdriver run execute_script error:Cannot read property 'style' of undefined

I am using selenium-python bindings to do some basic browser testing. I need to click an element, which is invisible by default.So I want make the invisible element visible,I have tried to use execute_script()monthod to make it visible by using the following code.However the JS code document.getElementsByClassName("bdpfmenu")[0].style.display="block"; run successfully within Console,but it occurs error massages when I use execute_script()with python
js = 'document.getElementsByClassName("bdpfmenu")[0].style.display="block";'
driver.execute_script(js)
and the error message:
selenium.common.exceptions.WebDriverException: Message: unknown error: Cannot read property 'style' of undefined
You can get the style attribute and compare.
document.getElementsByClassName("bdpfmenu")[0].getAttribute("style")

Sid.js: Uncaught TypeError: Cannot read property 'appendChild' of undefined

I've made some changes to my previously working XHTML document to better organise the Javascript, and now Sid.js is having a fit when it attempts to append Javascript documents to the head.
In Chrome I'm getting
Uncaught TypeError: Cannot read property 'appendChild' of undefined
On this line in Sid.js
scope.appendChild(node);
The problem is that
scope = (scope ? (scope == 'body' ? body : head) : (type == 'js' ? body : head));
is undefined.
Moved js files into body and it's fixed. Seems hacky.

SVG cause a row of errors thrown in Chrome console

A static page with pure JS and HTML and a svg file inserted in an "object" tag, everything is fine, but in one point I have noticed a stack of errors in the console. Everything works, but anyway I would like to understand the origin of it.
I tried to move file, clear cache, attaching svg using JS code at the end of page load, removing all of JS leaving file in pure HTML, removing reference to the CSS file in the svg itself, the error is always the same and it doesn't show only when the svg is out.
Google Chrome Version 38.0.2125.58 beta on linux peppermint os three,
I didn't noticed anything like that in FF and I didn't test other browsers. Greetings
Error in event handler for (unknown): Cannot read property 'addEventListener' of null
Stack trace: TypeError: Cannot read property 'addEventListener' of null
at initialize (chrome-extension://mdgdbmohcdjfbglkepkiaabaieenhhhc/inject.js:367:16)
at handleMessage (chrome-extension://mdgdbmohcdjfbglkepkiaabaieenhhhc/inject.js:58:5)
at EventImpl.dispatchToListener (extensions::event_bindings:397:22)
at Event.publicClass.(anonymous function) [as dispatchToListener] (extensions::utils:93:26)
at EventImpl.dispatch_ (extensions::event_bindings:379:35)
at EventImpl.dispatch (extensions::event_bindings:403:17)
at Event.publicClass.(anonymous function) [as dispatch] (extensions::utils:93:26)
at dispatchOnMessage (extensions::messaging:304:22) extensions::uncaught_exception_handler:9
handler extensions::uncaught_exception_handler:9
exports.handle extensions::uncaught_exception_handler:15
EventImpl.dispatch_ extensions::event_bindings:384
EventImpl.dispatch extensions::event_bindings:403
target.(anonymous function) extensions::SafeBuiltins:19
publicClass.(anonymous function) extensions::utils:93
dispatchOnMessage extensions::messaging:304

Categories

Resources