Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get css() property before append()?

Tags:

jquery

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
like image 810
clarkk Avatar asked Jun 17 '11 11:06

clarkk


People also ask

How do I retrieve the properties of a CSS element?

Get a CSS Property Value You can get the computed value of an element's CSS property by simply passing the property name as a parameter to the css() method. Here's the basic syntax: $(selector). css("propertyName");

How can give multiple CSS properties in jQuery?

To define multiple CSS attributes in jQuery, use the css selector or the addClass() method.

Does the order of properties matter in CSS?

CSS Order Matters In CSS, the order in which we specify our rules matters. If a rule from the same style sheet, with the same level of specificity exists, the rule that is declared last in the CSS document will be the one that is applied.


1 Answers

If it's not in the DOM, then you can't, AFAIK.

like image 168
Grant Thomas Avatar answered Nov 03 '22 00:11

Grant Thomas