Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7904715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T10:12:00+00:00 2026-06-03T10:12:00+00:00

function updateOption(selection, option) { jQuery(‘body,html’).animate({ scrollTop: jQuery(#msg).offset().top }, 800); jQuery(‘.’+selection).each(function() { jQuery(img.+selection).removeClass(optionSelected); }); jQuery.ajax({

  • 0
function updateOption(selection, option) {
        jQuery('body,html').animate({
            scrollTop: jQuery("#msg").offset().top
        }, 800);
        jQuery('.'+selection).each(function() {
            jQuery("img."+selection).removeClass("optionSelected");
        });
        jQuery.ajax({
            type: "GET",
            url: "../v1_include/v1_session_boutique.inc.php",
            data: selection + "=" + option,
            success: function(msg){
                jQuery('#msg').fadeIn('fast');
                var List = document.getElementById('msg');
                List.innerHTML = msg;
                  jQuery(".StoreMsgPanier").animate( { opacity: 0.25 }, 1000)
                    .animate( { opacity: 1 }, 1000);
            }
        });
}


<p>Option 1</p>
<div id="opt3">
    <a href="javascript:updateOption('select_1_3','1-5-1');"><img src="../v1_images_option/crop/5_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_3 optionSelected" /></a>
    <a href="javascript:updateOption('select_1_3','1-6-1');"><img src="../v1_images_option/crop/6_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_3" /></a>
</div>
<p>Option 2</p>
<div id="opt2">
    <a href="javascript:updateOption('select_1_2','1-3-1');"><img src="../v1_images_option/crop/3_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_2" /></a>
    <a href="javascript:updateOption('select_1_2','1-4-1');"><img src="../v1_images_option/crop/4_1.jpg" alt="" style="margin:2px;padding:5px;border:1px solid #D6D6D6" class="select_1_2" /></a>
</div>

This code works fine but how can I, after removing all ‘optionSelected’ class, add ‘optionSelected’ ONLY to the image I just clicked ?

Thanks for your help…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T10:12:02+00:00Added an answer on June 3, 2026 at 10:12 am

    You can either pass this from the caller and use it inside the function,

    Markup: Added this to the updateOption function call

        <a href="javascript:updateOption('select_1_3','1-5-1', this);">
    

    JS: Changed to _this.find(..

      function updateOption(selection, option, _this) {
        //..
        //...
           $(_this).parent().find("img").removeClass("optionSelected"); //remove class for all images
           $(_this).find("img").addClass("optionSelected"); //add class to the image inside the link
    

    Alternatively, It is good practice to use unobtrusive way.. See below,

    Markup: Added this to the updateOption function call

    <p>Option 1</p>
    <div id="opt3">
        <a href="javascript: void(0)" data-opt="1-5-1" data-sel="select_1_3"><img src="../v1_images_option/crop/5_1.jpg" alt="Image" class="select_1_3 img_style optionSelected" /></a>
        <a href="javascript: void(0);" data-opt="1-6-1" data-sel="select_1_3"><img src="../v1_images_option/crop/6_1.jpg" alt="Image" class="select_1_3 img_style" /></a>
    </div>
    <p>Option 2</p>
    <div id="opt2">
        <a href="javascript: void(0)" data-opt="1-3-1" data-sel="select_1_2"><img src="../v1_images_option/crop/3_1.jpg" alt="Image" class="select_1_2 img_style" /></a>
        <a href="javascript: void(0)" data-opt="1-4-1" data-sel="select_1_2"><img src="../v1_images_option/crop/4_1.jpg" alt="Image" class="select_1_2 img_style" /></a>
    </div>
    

    CSS:

    .img_style { margin:2px;padding:5px;border:1px solid #D6D6D6; }
    

    And finally the JS: Bunch of modification, please try to understand it before you implement it.

    $(function() {
        $('.img_style').click(function() {
            $('body,html').animate({
                scrollTop: $("#msg").offset().top
            }, 800);
    
            var $this = $(this);        
    
            $this //current link
            .closest('div') //will return you the enclosing div lets say <div id="opt2">
            .find('img') //find all images inside <div id="opt2">
            .removeClass("optionSelected"); //remove class
    
            $this.addClass('optionSelected');
    
            var $parent = $this.parent();
    
            var option = $parent.attr('data-opt'); //will return you the option
            var selection = $parent.attr('data-sel');
    
            $.ajax({
                type: "GET",
                url: "../v1_include/v1_session_boutique.inc.php",
                data: selection + "=" + option,
                success: function(msg) {
                    $('#msg').fadeIn('fast').html(msg);
    
                    $(".StoreMsgPanier").animate({
                        opacity: 0.25
                    }, 1000).animate({
                        opacity: 1
                    }, 1000);
                }
            });
        });
    });
    

    DEMO -> To show that the option and selection is retrieved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

function SendInfo(href) { var subject= Some information; var body = I thought you might
function dowork() { $(.wrappedElement).removeClass(wrappedElement); $(.wrappedElementout).removeClass(wrappedElementout); var a=$(div#DepPart select option:selected).val(); $(div#TestPart select option[value^=a]).addClass(wrappedElement); $(div#TestPart select
Hallo, i am new to jquery, AJAX requests. Here is my html code in
function get() { $.post( 'postchatfame.php', { comment: postchatfamemsg.comment.value, userid: postchatfamemsg.userid.value }, function(output) { $('#walls').html(output).show();
I have two selection fields; <label>Color:</label> <select id=color> <option value=red>Red</option> <option value=blue>Blue</option> </select> <label>Car:</label>
function contentDisp() { $.ajax({ url : a2.php, success : function (data) { $(#contentArea).html(data); }
function toggleLinkSelection(link){ if($(link).css('border-top-color') == 'red'){ $(link).css({'border-top-color': 'transparent'}); } else { $(div[id$='OptionsLink']).css({'border-top-color': 'transparent'}); $(link).css({'border-top-color': 'red'});
function moveto(step1, step2, step3) { var w = $(document).width(); var h = $(document).height(); $('#full').animate({
function readArgs() { while getopts i:o:p:s:l:m OPTION; do case $OPTION in i) input=$OPTARG ;;
function deleteRecordDialog() { var returnThis; var numRecordss = recs.length; var html = /*html= html

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.