LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 02-07-2008, 05:52 PM   #1
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 407

Rep: Reputation: 30
getElementById doesn't work in IE when element is created after page load


Hi,

I have a page with 3 tabs made from YUI tabview functions. The content of each tab is created using asynchronous request to the server.

When I try to find some of the elements inside each tab by using getElementByID, IE and Opera say it's a null element, while FF shows the correct element. I even tried a function in YUI to see if such element exist in a page, and it returned true in FF, but Opera and IE returned false.

PHP Code:
var score=YAHOO.util.Dom.hasClass('news_comment_796''divComment');    
alert(score); 
Any idea how to find an element which is loaded in a page, after whole page is loaded?
 
Old 02-08-2008, 05:22 PM   #2
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
This can ber several things, are there two elements with the same id?
Are the names generated the same in all browsers? (Don't forget your dealing with three diffrent scripting engines here and they all have their quirks.)
Is the element set visible="false"? (Catches a lot of people out this one, thats why we have display:none )

You could also do a tagName search to check if its their at all.
Code:
function CheckId()
{
    var element = document.getElementById( "news_comment_796" );
    if( element != null )
    {
        alert( "Found element by getElementById" );
        return;
    }

    var elements = document.getElementsByTagName( "div" );
    for var i = 0; i < elements.length; ++i )
    {
        if( elements[i].id == "news_comment_796" )
        {
            alert( "Found element with id with search" );
            return;
        }
    }
    alert( "No matching Id Found" );
}
 
Old 02-09-2008, 05:18 AM   #3
mohtasham1983
Member
 
Registered: Apr 2005
Location: San Jose
Distribution: Fedora 3,4- Ubuntu 6.06 to 8.10, Gentoo and Arch
Posts: 407

Original Poster
Rep: Reputation: 30
Thank you for response. I'm using xslt to generate my html and I'm not much experienced in it.

I defined a simple div element with a fixed name inside my tab content and could found it in DOM using all browsers. That is, I realized there is something wrong with xslt, generating dynamic names for div element. I was assigning ID to each div element in xslt like the following which was causing the error:

PHP Code:
<div class="divComment">
<
xsl:attribute name="id">                                
news_comment_<xsl:value-of select="news_id"/>    
</
xsl:attribute>
</
div
What I did was to store the value of news_id in an xslt variable and then simply call its value like this:

PHP Code:
<div class="divComment" id="news_comment_{$news}">
</
div
I know that this post will remain in LQ forever. So I hope it helps anyone with similar problem.
 
  


Reply

Tags
ajax, ie, javascript


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
page load time ygloo LQ Suggestions & Feedback 5 10-04-2006 11:03 AM
IE cutting a web page created using Dreamweaver julian_s General 6 02-01-2006 08:08 PM
GTK+ Related I *think* GNOME won't load, no graphical element to RedHat 9... nutnut Linux - Software 2 02-26-2005 07:33 AM
HTML setting focus on a form element on load patpawlowski Programming 3 02-24-2004 10:01 AM
page load emulation aizkorri Linux - Software 4 06-25-2003 04:55 AM


All times are GMT -5. The time now is 04:38 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration