css - Javascript - getElementById returning null despite elements with given IDs existing on page -


Many functions to show and hide different divs on the page by applying style classes named "hidden" and "hidden" This function is to hide several divs at once using "visible" setAttribute. Each "div" is listed in an array with the "hidden" class given ID.

Each div can have more than one class, so when a div is given a "hidden" square, then it should be protected, except the "visible" class, to the other class (sas) . function theater section () {// Initialise array with div IDs var divs = new array ("tab-1", "tab-2" , "Tab-3", "Tab-4", "Tab-5"); // for loop through divs in array (var number = 0; calculation & lt; divs.length; count ++) {// get current classes var div = document.getElementById (divs [count]); Var divClass = div.getAttribute ("square"); // Remove the "visible" square if it is divClass = divClass.replace ("visible", ""); // attach the "hidden" category div.setAttribute ("square", divClass + "hidden"); }}

For some reason this function is not working, although it is definitely being called.

A warning is placed inside the loop, line [[var divClass = div.getAttribute ("square");]] kept after this line, it is not so, so I guess this line Impose where the problem is.

A class attribute is specified in all divs.

Text => text-mail "itemprop =" text ">

My guess is that you have elements that do not have any class attributes, so DivClass is zero - there is an error on the line DivClass = divClass.replace ("visible", ""); . (Can not call a method with an empty value)

Try to check the attribute:

  // div with initial array var divs = New array ("tab -1", "tab-2", "tab-3", "tab-4", "tab-5"); // for loop through divs in array (var number = 0; calculation & lt; divs.length; count ++) {// get current classes var div = document.getElementById (divs [count]); Var divClass = ''; If (divClass = div.getAttribute ("class")) {// Remove "visible" class if it is divClass = divClass.replace ("visible", ""); } // Divide the "hidden" square div.setAttribute ("square", divClass + "hidden"); }   

... or you can check out.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -