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

  • Home
  • SEARCH
  • 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 7025323
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:57:33+00:00 2026-05-27T23:57:33+00:00

I am currently using this code for several images: <script> $(function () { $(img.cat).click(function()

  • 0

I am currently using this code for several images:

<script>
$(function () {
$("img.cat").click(function() {
$(this).css('border', "solid 2px #ff0000");  
});
});
</script>

The code works fine but I only want 1 image bordered at a time. So is there any way to modify the code so that it clears all borders or even add a white border so it’s not visible to add the images with class “cat” and then add the red border to the latest clicked image?

  • 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-05-27T23:57:34+00:00Added an answer on May 27, 2026 at 11:57 pm

    You can do this:

    $(function () {
        $("img.cat").click(function() {
            $("img.cat").css("border","none"); // erases the border on other images
            $(this).css('border', "solid 2px #ff0000");  
        });
    });
    

    You just select all the images with the same class again and remove their borders, then continue with setting the border of the one that was just clicked.

    Also, as long as you’re using jQuery 1.7 (you can use delegate() for earlier versions), then it’s recommended that you use on() to attach event handlers. This would look like this:

    $(document).on("click", "img.cat", function(){
        $("img.cat").css("border","none");
    });
    

    To make it more efficient, you could select the closest parent element that all the elements share. For example, if the images were all children of a div with the id imageContainer, you would do this:

    $("#imageContainer").on("click", "img.cat", function(){
        $("img.cat").css("border","none");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently using this code to calculate the sunrise / sunset times. (To be
I am a rank beginner in C#. I am currently using this code: objGraphics.Clear(SystemColors.Control);
I am currently using code similar to this: try { // IE ONLY var
Using dotnet 2.0. I currently have code like this : DataView dv = new
I am currently using a code construction like this: string line; using (System.IO.StreamReader file
I am currently using this code in my App Delegate to set a custom
I'm using several PNG images (via CSS) into a site's template, xhtml and CSS,.
Why does this code fail to display the category name Apples using the current
I'm currently using this jQuery validate plugin and having an issue in IE where
I'm currently using this method in calling batch files in vb.net: Private Sub Button3_Click(ByVal

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.