Wordpress Theme - Debt Consolidation - Debt Consolidation - Debt Consolidation - Online Advertising

PDA

View Full Version : AJAX Content Generation


wellmoon
Feb 13th 2007, 7:40 am
Hi,

I'm using AJAX to get a list of filenames from the server and create buttons based on which filenames the script finds, so if it finds one file in the specified directory it will generate and add one button to the page, then the intention is that clicking that button will load some more content.

In FireFox, everything works fine, the new buttons that are generated pick up the stylerules for them and the content loads when they are clicked.

In IE however, the new buttons do not pick up the style rules associated to them and do nothing when clicked. The IE DOM browser shows that the generated buttons do have the correct class and onclick attributes given to them using setAttribute() at creation time so I can't understand why it's not working with IE.

The code I'm using to create the buttons is:

var newbutton = document.createElement("button");
var myonclick = "showContent()";
var newbuttonstyle = "newbutton";
newbutton.setAttribute("onclick", myonclick);
newbutton.setAttribute("class", newbuttonstyle);


Any ideas/suggestions hugely appreciated...

ajsa52
Feb 13th 2007, 11:57 am
With the library prototype.js (cross browser compatible) you can use:
- For replacing setAttribute("onclick", myonclick) -> observe() function. It's a extension for the Event object. Use: observe(element, name, observer, useCapture)
- For replacing setAttribute("class", newbuttonstyle) -> addClassName() function. Use: addClassName( element, className)

wellmoon
Feb 14th 2007, 12:18 pm
thanks ajsa52 but I want to do it without using a js library...