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');

              $('#pic4').attr("src", "images/leaf_shapes/23/leafbg_13.gif");
              $('#leafshown').attr('class',chosen_leaf); // THIS doesn't work
             //  $('#leafshown').addClass(chosen_leaf); THIS WORKS


Recommended Answers

All 2 Replies

Member Avatar

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.


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, learning, and sharing knowledge.