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
- get width of the the TD where the INPUT has to be appended…
- get the left and right padding of the INPUT
- append the INPUT to the TD with the width of the TD minus the left and right padding of the INPUT
You could insert a hidden input, with the class, get the css properties and the use them.
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
Alternatively there is a css only solution but it does not work in IE7 and below