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 6982457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:17:27+00:00 2026-05-27T18:17:27+00:00

I have many divs with the same class and inside of divs contain a

  • 0

I have many divs with the same class and inside of divs contain a image:

<div class="card_div"> 
<img src="path" alt="name_image"> 
</div> 
<div class="card_div"> 
<img src="path" alt="name_image"> 
</div> 
<div class="card_div"> 
<img src="path" alt="name_image"> 
</div> 
<div class="card_div"> 
<img src="path" alt="name_image"> 
</div> 
.
.
.

I want find a img that if the image’s width its less than 200px add a class only to this img less than 200px width.

For example:

var imgWidth = $(".card_div img").width();
if (imgWidth < 200) {
$(".card_div img").css({margin:"8px 8px 8px 17px", "background-color":"blue"});  
}

But this code add the margin and background to every image divs I can not change the divs name. Every divs have same name.

I want only add the css propierty to img that its less than < 200.

Its possible? Thank you

  • 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-27T18:17:28+00:00Added an answer on May 27, 2026 at 6:17 pm

    The HTML Markup that you posted is not the best, but using that exact markup I’ve setup this example of how you would achieve your desired result: http://jsfiddle.net/xFSLN/1/

    HTML:

    <div class="card_div"><img src="http://placekitten.com/199/199" alt="name_image"></div> 
    <div class="card_div"><img src="http://placekitten.com/200/200" alt="name_image"></div> 
    <div class="card_div"><img src="http://placekitten.com/300/300" alt="name_image"></div> 
    <div class="card_div"><img src="http://placekitten.com/100/100" alt="name_image"></div> 
    

    CSS:

    .under-200 {
        margin: 8px 8px 8px 17px;
        background-color: blue;
    }
    

    Javascript:

    $('div.card_div]').find('img').each(function () {
         var $this = $(this), width = $this.width();
        if (width < 200) {
            $this.addClass('under-200');
        }
    });
    

    I would highly recommend that you change the HTML to be more valid.

    1. All of your IDs should be unique
    2. Don’t include the ‘#’ in your ID
    3. Use Class Names when Appropriate

    UPDATED: You updated your markup to be improved. I’ve updated the answer to reflect your changes.

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

Sidebar

Related Questions

i have many div's with the same background image and i want change this
I have container did and there are many divs inside that div. In one
I have a page with many elements that have the same class attached to
I have many inputs in a few divs, every div is being hidden and
I have many DIVs, let's say 100, split by categories like that : <div
I have a page (myPage.aspx) that contains a number of divs. EG. <div class=quote>something
I have a bunch of elements like the following: <div class=droppableP id=s-NSW style=width:78px; height:63px;
I have a view with a div that is looped many times. Each of
say I have a css class name div.TestClass { float:left;etc// } span.SpanTestClass { float:right;etc//
I have an INPUT text field, a DIV and an IMG. The IMG has

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.