Results 1 to 5 of 5

Thread: javascript ie7/firefox/opera/Konqueror

  1. #1
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts

    javascript ie7/firefox/opera/Konqueror

    Code:
    // Display the next hidden box in a series of related items
    function showbox(type){
    	var divs = document.getElementsByTagName('div');
    	var el, i = divs.length;
    	while( i-- ){
    		el = divs[i];
    		if(el.getAttribute('class') == type){
    			alert("this doesnt show in ie7");
    			if(el.style.display == 'none'){
    				el.style.display = 'block';
    				break;
    			}
    		}
    	}
    }
    I use the above code to show the first hidden div in a series of related divs (i.e. so running the script 5 times will show 5 of the divs)

    Code:
    if(el.getAttribute('class') == type)
    that line works as expected in opera/firefox/konqueror, but not in IE7. Is there a universal alternative?

    Cheers!

  2. #2
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: javascript ie7/firefox/opera/Konqueror

    Does it throw up a javascript error? If not you might have to access the attribute collection of el and reference the class attribute through an index, if you do it may be because IE7 has a problem with using getElementsByTagName on a DOM representation of a tag.
    To err is human. To really foul things up ... you need a computer.

  3. #3
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts

    Re: javascript ie7/firefox/opera/Konqueror

    Cheers Yam,

    nopes no error (i assume I'd get a warning icon on the status bar?). I use firebug for firefox to debug stuff and that's not showing any errors either.

    I think I get what you mean. I have to define el differently to make IE7 able to see it's properties?

  4. #4
    Large Member
    Join Date
    Apr 2004
    Posts
    3,720
    Thanks
    47
    Thanked
    99 times in 64 posts

    Re: javascript ie7/firefox/opera/Konqueror

    Yes, try alerting the nodeName of the index of an attribute in the attribute collection
    Code:
    alert(el.attributes[x].nodeName);
    If it is blank then i'm afraid you will have to find an alternative means of retreiving your divs (an alternative to 'DOMObject.getElementsbyTagName'). Bear in mind attributes are parsed 'backwards', that is if the attribute 'id' is the 3rd and last element in a tag, then it will have an index of 0 in the attribute collection. Your first alternative would be to use the className property instead:
    Code:
    if(el.className == type) { ...
    This should be a suitable solution as fas i can tell.
    Last edited by yamangman; 24-10-2007 at 07:14 PM.
    To err is human. To really foul things up ... you need a computer.

  5. Received thanks from:

    Raz316 (25-10-2007)

  6. #5
    Funking Prink! Raz316's Avatar
    Join Date
    Jul 2003
    Location
    Deal, Kent, UK
    Posts
    2,978
    Thanks
    130
    Thanked
    62 times in 52 posts

    Re: javascript ie7/firefox/opera/Konqueror

    Awesome thanks : D

    el.className is exactly what I was after and it now works in all browsers. Cheers!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Javascript help???
    By MagicFreebiesUK in forum Help! Quick Relief From Tech Headaches
    Replies: 0
    Last Post: 21-03-2007, 03:07 PM
  2. Replies: 6
    Last Post: 22-11-2006, 02:58 PM
  3. Replies: 2
    Last Post: 06-11-2006, 12:05 PM
  4. javascript not displaying in firefox
    By ZigZag in forum Software
    Replies: 3
    Last Post: 11-09-2005, 12:05 PM
  5. Javascript problem
    By Korky in forum PC Hardware and Components
    Replies: 0
    Last Post: 03-04-2004, 12:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •