First up, you can wrap your newly created nodes in $ and use jQuery methods.

Instead of:

       var listLabel = document.createElement( 'label' );
       listLabel.style.display = '-moz-inline-box';
        listLabel.style.textAlign = 'left';

Do:

       var listLabel = document.createElement( 'label' );
       $(listLabel).css({display: "-moz-inline-box", textAlign: "left"})

On 10/26/06, smeranda <[EMAIL PROTECTED]> wrote:

I am trying to add a class (.currenttotal) to a dynamically generated span
 

element. How can I do this?

Basically, I am pulling an xml file and using the information to create an
interface. I need to add the .currenttotal class to the registeredSpan. Any
ideas?

$("majorname", xml).each(function(i){
        var listItem = document.createElement( 'li' );
        var listLabel = document.createElement( 'label' );
        listLabel.style.display = '-moz-inline-box';
        listLabel.style.textAlign = 'left';
        var labelSpan2 = document.createElement ( 'span' );
        labelSpan2.style.display = 'block';
        labelSpan2.style.width = '120px';
        labelSpan2.innerHTML = $(this).text();
        var listInput = document.createElement( 'input' );
                listInput.name = $(this).text();
                listInput.value = '3';
        var registeredSpan = document.createElement( 'span' );
                $(registeredSpan).addClass("currenttotal"); //This doesn't work.
        listLabel.appendChild( labelSpan2 );
        listItem.appendChild( listLabel );
        listItem.appendChild( listInput );
        listItem.appendChild( registeredSpan );
        $("#appointmentList").append( listItem );
});

If there is a better way to write the above code, I'm open to suggestions!
--
View this message in context: http://www.nabble.com/Adding-class-to-dynamic-element-tf2517168.html#a7020780
Sent from the JQuery mailing list archive at Nabble.com.


_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/



--
Yehuda Katz
Web Developer | Wycats Designs
(ph)  718.877.1325
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to