Hi all I am trying to add a class selected to click area and a remove class in the hide area for the below jquery/javascript. Not really undstanding how it's added.

Thanks in advaance

D

  <script type="text/javascript">
        $(document).ready(function(){
            $('.partner_image').click(function() {
               var id =$(this).class('selected');
               var id = $(this).attr('id');
               id = id.replace('partner_','');
               console.log(id);

              $('.partner_description').hide();
              var description = $('#partner_description_' + id);
              $(description).show();
                });

            });

        </script>

Recommended Answers

You're looking for addClass and removeClass

Jump to Post

All 3 Replies

Hi EvolutionFallen thanks for the reply I have added the elements in bold don't seem to work yet am I on the correct track.

Thanks in advance

D

 <script type="text/javascript">
        $(document).ready(function(){
            $('.partner_image').click(function() {
               var id = $(this).attr('id');
               id = id.replace('partner_','');
              ** $(this).addClass("selected"); **
               console.log(id);

             $('.partner_description').hide();
              var description = $('#partner_description_' + id);
             ** $(this).removeClass("selected"); **
              $(description).show();
                });
            });
        </script>

Can you show the HTML, and indicate what you're trying to show/hide?

Be a part of the DaniWeb community

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