Note that there are some explanatory texts on larger screens.

plurals
  1. POInternet Explorer 7 - Javascript 'undefined' not testing
    primarykey
    data
    text
    <p>I'm having trouble with some JS in IE7. I'm testing to see if a certain object has a className (its possibly an HTMLElement object from the DOM) assigned.</p> <p>Now, testing the page in Firefox tells me that Yes, the variable is undefined (all my tests below do the Alert(). </p> <p>In IE, none of the tests pass, the variable gets assigned on the last IF statement, and during the last Alert() IE chucks an "className is null or not an object" error, based on the <code>fn_note.className</code> statement.</p> <p>Here's the code:</p> <pre><code> var fn_note; var kids = area.childNodes; for (var l = 0; l &lt; kids.length; l++){ //DEBUG check if the found var exists if (kids[l].className == null){ //then the className var doens't exist alert ('the classsname for the following var is null: --'+kids[l]+'--'); } if (kids[l].className == undefined){ //then the className var doens't exist alert ('the classsname for the following var is undefined: --'+kids[l]+'--'); } if (kids[l].className == ''){ //then the className var doens't exist alert ('the classsname for the following var is an empty string: --'+kids[l]+'--'); } if (typeof kids[l].className === 'undefined'){ //then the className var doens't exist alert ('the classsname for the following var is NEW TYPEOF TEST: --'+kids[l]+'--'); } if (kids[l].className == 'fn-note') { /* (/fn-note$/).test(kids[l].className) IE doesn't really like regex. por supuesto */ //we have found the div we want to hide fn_note = kids[l]; } } alert('the clicked on className is '+area.className+'name of the found div is '+fn_note.className); </code></pre> <p>Please let me know what I am doing wrong. I know its probably something basic but I just can't see it ATM.</p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload