473,395 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

DOM methods showing different results in IE

143 100+
Hi...

I'm "ajaxifying" my image gallery and I have some code which creates the elements on the fly and places them on the page.

Using firefox, the code works fine and the elements show up as they should, however in IE, the UL and LI's appear to have no style associated with them at all and don't display as they should.

They are styled with CSS and it's the same layout as the non ajax version, which works fine in IE.

The way the html should look after javascript:

[HTML]<h1>Photo album: France, July 2006</h1>
<span id="page_count">Page 1 of 5</span>
<ul id="gallery">

<li class="imgcontainer" title="Yaron and yup, that's the Catheral Notre Dame de Paris... again.">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=1">
<img src="data/thumbs/album_44_image_306.jpg" alt="" width="80" height="60" />

</a>
</div>
</li>

<li class="imgcontainer" title="">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=2">
<img src="data/thumbs/album_44_image_307.jpg" alt="" width="80" height="60" />
</a>
</div>

</li>

<li class="imgcontainer" title="">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=3">
<img src="data/thumbs/album_44_image_308.jpg" alt="" width="60" height="80" />
</a>
</div>
</li>

<li class="imgcontainer" title="">

<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=4">
<img src="data/thumbs/album_44_image_309.jpg" alt="" width="60" height="80" />
</a>
</div>
</li>

<li class="imgcontainer" title="">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=5">

<img src="data/thumbs/album_44_image_310.jpg" alt="" width="80" height="60" />
</a>
</div>
</li>

<li class="imgcontainer" title="">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=6">
<img src="data/thumbs/album_44_image_311.jpg" alt="" width="60" height="80" />
</a>

</div>
</li>

<li class="imgcontainer" title="Yaron wanted all these pics... seriously.">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=7">
<img src="data/thumbs/album_44_image_312.jpg" alt="" width="60" height="80" />
</a>
</div>
</li>


<li class="imgcontainer" title="">
<div>
<a href="/simpleTEST/www/?pid=2&amp;a=44&amp;im=8">
<img src="data/thumbs/album_44_image_313.jpg" alt="" width="80" height="60" />
</a>
</div>
</li>

</ul>
<p id="img_desc">

I have a couple of great friends... Mike and Yaron drove over to France with me to help shift my stuff when I moved here.
</p>[/HTML]

The javascript which creates this html:

Expand|Select|Wrap|Line Numbers
  1.       if (galleryObj) {
  2.         clearInterval(timer);
  3.  
  4.         galleryTitle = dom.newElement(d, "h1");
  5.         galleryTitle.appendChild(dom.addText(d, "Photo album: " + galleryObj.gallery.title));
  6.  
  7.         galleryPage  = dom.newElement(d, "span");
  8.         galleryPage.setAttribute("id", "page_count");
  9.  
  10.         thumbnailUl  = dom.newElement(d, "ul");
  11.         thumbnailUl.setAttribute("id", "gallery");
  12.  
  13.         galleryDesc  = dom.newElement(d, "p");
  14.         galleryDesc.setAttribute("id", "img_desc");
  15.         galleryDesc.appendChild(dom.addText(d, galleryObj.gallery.desc));
  16.  
  17.         for (var i = 0; i < galleryObj.gallery.thumbs_per_page; i++) {
  18.           if (image = galleryObj.gallery.image[i]) {
  19.             thumbnailLi  = dom.newElement(d, "li");
  20.             thumbnailLi.setAttribute("class", "imgcontainer");
  21.             thumbnailDiv = dom.newElement(d, "div");
  22.             thumbnailA   = dom.newElement(d, "a");
  23.             thumbnailImg = dom.newElement(d, "img");
  24.             thumbnailA.setAttribute("href", "javascript: simple.enlarge(" + image.img_id + ")");
  25.             thumbnailImg.setAttribute("src", image.thumb);
  26.             thumbnailImg.setAttribute("alt", image.desc);
  27.             // append elements
  28.             thumbnailA.appendChild(thumbnailImg);
  29.             thumbnailDiv.appendChild(thumbnailA);
  30.             thumbnailLi.appendChild(thumbnailDiv);
  31.             thumbnailUl.appendChild(thumbnailLi);
  32.           }
  33.         }
  34.  
  35.         // display after a delay
  36.         setTimeout(function() {
  37.           d.getElementById('content').appendChild(galleryTitle);
  38.           d.getElementById('content').appendChild(galleryPage);
  39.           d.getElementById('content').appendChild(thumbnailUl);
  40.           d.getElementById('content').appendChild(galleryDesc);
  41.           // after work is done, hide loadingAnim and show thumbs
  42.           loadingAnim.style.display = "none";
  43.         }, 1000);
  44.      }

As you can see, I'm using DOM methods to create and add the elements to my HTML. Both IE6 and 7 appear to show the unordered list containing the thumbs with no style. The rest of the elements are styled as they should be.

Any ideas appreciated.

Thanks
Mar 9 '07 #1
3 1538
mrhoo
428 256MB
your line
thumbnailLi.setAttribute("class", "imgcontainer");
is fine for most browsers, but not ie.

To work in all browsers set the class as a property, not an attribute:
thumbnailLi.className="imgcontainer";
Mar 9 '07 #2
steven
143 100+
your line

is fine for most browsers, but not ie.

To work in all browsers set the class as a property, not an attribute:
thumbnailLi.className="imgcontainer";
Wow that's nuts, but it works! Thanks... I suppose this is only for classes, seeing as how the other elements using "id" work fine?

Excellent... oh, one more question.

I wrote a small simple tooltip class and I assign an event to <a> tags on the page. I use the standards method of obj.addEventListener(event, func, false); and obj.attachEvent('on'+event, func); for W3C browsers and IE, respectively - however, the event only passes the object to the function call in good browsers. In IE, the function that's called has no access to the object. Instead, I have to use the .onmouseover = funcName;

Any idea why?

Thanks
Mar 9 '07 #3
steven
143 100+
Ok, I figured I'd just post an answer to my second question:

from http://www.quirksmode.org/js/events_advanced.html

When compared to the W3C model, the Microsoft model has two important drawbacks:

1. Events always bubble, no capturing possibility.
2. The event handling function is referenced, not copied, so the this keyword always refers to the window and is completely useless.
Sigh
Mar 9 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

99
by: David MacQuigg | last post by:
I'm not getting any feedback on the most important benefit in my proposed "Ideas for Python 3" thread - the unification of methods and functions. Perhaps it was buried among too many other less...
125
by: Raymond Hettinger | last post by:
I would like to get everyone's thoughts on two new dictionary methods: def count(self, value, qty=1): try: self += qty except KeyError: self = qty def appendlist(self, key, *values): try:
60
by: Eric | last post by:
I thought it might be fun to run a simple vote to discover the most preferred spacing style for a simple if statement with a single, simple boolean test. By my count, there are 32 possible...
9
by: Clint | last post by:
Hey all - Excuse the cross-post ... I'm not sure what the appropriate newsgroup would be for this question. I have a question that I'm not quite sure how to ask. For all I know, I have the...
2
by: jjouett | last post by:
We are starting to setup some Web Services to provide our customers with a way to programatically interact with our application, and some of our customers have slightly different requirements in...
3
by: adebiasio | last post by:
I have an application that has various libraries. One of them I use shared methods in a class A to have all libriares access these methods. This seems to work with no problems. However, I am...
26
by: Cliff Williams | last post by:
Can someone explain the pros/cons of these different ways of creating a class? // 1 function myclass() { this.foo1 = function() {...} } // 2a
10
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that...
1
by: Andrus | last post by:
Are Linq-SQL methods commutative ? Should the following queries return same or different results ? var query = query.Skip(n).Take(m); var query = query.Take(m).Skip(n); Andrus.
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.