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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:38:33+00:00 2026-05-23T07:38:33+00:00

how can you get a css property before the element is appended? css input.inp

  • 0

how can you get a css property before the element is appended?

css

input.inp {
    padding:3px 2px 3px 2px;
}

js

var elm = $('<input class="inp" type="text" />');

alert(elm.css('padding-left'));
td.append(elm);
alert(elm.css('padding-left'));

only the second alert retuns the value…

I want the input element to have width:100%.. but since you can’t do that (when the input has a padding of its own) I need to set the width in pixels

  1. get width of the the TD where the INPUT has to be appended…
  2. get the left and right padding of the INPUT
  3. append the INPUT to the TD with the width of the TD minus the left and right padding of the INPUT
  • 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-23T07:38:33+00:00Added an answer on May 23, 2026 at 7:38 am

    You could insert a hidden input, with the class, get the css properties and the use them.

    <input id="getPadding" class="inp" type="text" style="display:none" />
    

    Then after the element is appended You can just get the elements parent width and then set the input to that width minus the amount of padding.. Like so

     $('td input').width($(this).parent().width() - [$('#getPadding').css('padding-left') + $('#getPadding').css('padding-right')])
    

    Alternatively there is a css only solution but it does not work in IE7 and below

    td input {
        margin: 0px;
        width: 100%;
        height: 100%;
        border: 0px;
        display: block;
        padding: 2px 5px;
        -moz-box-sizing: border-box;
        -ms-box-sizing: border-box;
        -webkit-box-sizing: border-box;
        box-sizing: border-box;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to get needed css property of element (properties may be inherited from
How can I drop the CSS property ::-webkit-scrollbar from a single HTML element? In
I know you can SET multiple css properties like so: $('#element').css({property: value, property: value});
I can't get CSS to apply to the function below. Is it because it's
Where can I get some decent looking free ASP.Net or CSS themes?
How can I get superscript done, only in CSS? I have a stylesheet where
I want to apply some CSS to text that I can't get marked up
Are Regular Expressions useful for a Web Designer (XHTML/CSS)? Can a web designer get
Are there any tool/website where we can get the equivalent property in Mozilla of
I can't get the left property of an object i've tried $('myobject').left() //it doesn't

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.