Strange little glitch in a function. I need to replace a class for an element. I can add class, but I don't want that. I need to replace the class. And it's not working. The variable passes with .addclass. and not the other way. maybe there's some syntax I'm not understanding?

here's what I've got:

 $('#dropdown1a li').click(function(){

              var chosen_leaf = $(this).attr('id');

              $('#uniqueleaf').css({display:"block"},800);
              $('#pic4').attr("src", "images/leaf_shapes/23/leafbg_13.gif");
              $('#uniqueleaf').attr('class','chosen');
              $('#leafshown').attr('class',chosen_leaf); // THIS doesn't work
             //  $('#leafshown').addClass(chosen_leaf); THIS WORKS
              $('#uniquename').css({display:"block"},800);

       }); 
Member Avatar for stbuchok

What is the value of the class attribute after you assign chosen_leaf to it?

It gives no value. If I use .attr('class',chosen_leaf);, I get class=""
If I use .addClass(chosen_leaf);, I get class="_auriculate" or whatever other "_word" id that the clicked <li> has.

I suppose there's something like this maybe, that I could put first.

.removeclass(*),

But that seems extra-wordy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.