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
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to