Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
78
rated 0 times [  84] [ 6]  / answers: 1 / hits: 48127  / 12 Years ago, fri, february 8, 2013, 12:00:00

I am very new to Javascript.
I am having an error:




Uncaught TypeError: Cannot read property 'children' of null fiddle.jshell.net:1163
(anonymous function)




How to fix the error?



Providing my fiddle below:



http://jsfiddle.net/N3GTy/29/embedded/result/



var slider = new Swipe(document.getElementById('slider'), {
callback: function(e, pos) {

var i = bullets.length;
while (i--) {
bullets[i].className = ' ';
}
bullets[pos].className = 'on';

}
}),

bullets = document.getElementById('position').getElementsByTagName('em'),

// tabs
tabs = new Swipe(document.getElementById('tabs'), {
callback: function(event, index, elem) {
setTab(selectors[index]);
}
}),

selectors = document.getElementById('tabSelector').children;
Uncaught TypeError: Cannot read property 'children' of null

for (var i = 0; i < selectors.length; i++) {
var elem = selectors[i];
elem.setAttribute('data-tab', i);
elem.onclick = function(e) {
e.preventDefault();
setTab(this);
tabs.slide(parseInt(this.getAttribute('data-tab'), 10), 300);
}
}

More From » jquery

 Answers
18

There is no element with an id of tabSelector. So, document.getElementById('tabSelector') returns null. I tested this with chrome's debugger by going to:



http://fiddle.jshell.net/N3GTy/29/show/light/



and running two commands from the chrome debugger console:



document.getElementById('slider');
Returns a domNode as you would expect.



document.getElementById('tabSelector');
Returns null, because it does not exist.



calling null.children then results in your error.


[#80359] Wednesday, February 6, 2013, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jaylynkarinam

Total Points: 740
Total Questions: 103
Total Answers: 103

Location: Liechtenstein
Member since Wed, Dec 8, 2021
3 Years ago
;