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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T02:13:29+00:00 2026-06-13T02:13:29+00:00

I am prepending an image using to a span using .attr() and want to

  • 0

I am prepending an image using to a span using .attr() and want to add a top margin to the image only. But when I add css to the jquery, it moves the entire span, not just the image. I’ve twiddled around with this for awhile, but can’t figure it out.

How can I add CSS to the prepended image only and not to the entire span?

Here’s the code.

    $("<img />").prependTo('span.album:contains("Toto")').attr({
        src: '/images/toto.jpg',
        alt: '',
        height: '24',
                    style: 'margin-top:3px;' //this moves the whole span
    });
  • 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-13T02:13:31+00:00Added an answer on June 13, 2026 at 2:13 am

    When you change the margin of the image, it is increasing the height of the current line. Since the image and the span are display: inline, it will also increase the spacing above the span because they are both on the same line. Consider floating the image so that the image doesn’t increase the line height.

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

Sidebar

Related Questions

I'm using HighStock to generate some charts in browser. But now I want to
I am using Andy Langton's show/hide jQuery code but looks like the code has
I have a php script, which downloads, rescales and stores an image using the
I have implemented an image blending method for seamless blending using plain C++. Now
I have multiple images stored at URLs like: /uploads/hash/IMAGE001.jpg . Using jQuery UI's sortable()
I am trying to do something very simple. I want to display an image
I'm developing an Android App using PhoneGap, but I found a problem very soon.
I'm using google custom search to get image results. This is my first test
Using a method I've done before but having issues. Not sure if it's a
We're developing an app using Trigger.io in conjunction with Jquery Mobile 1.1.1. We're aware

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.