Trying to get the width of a sub-elements
Hi!
I need to get the width of a span.
The page contains many (or one...) pair of jean, and the price is in a span. I need to move dynamically the position of this span, using jquery.
What I do is getting the element of the table that contain the jean using JQUERY.
After that, I browse all elements of this table using jquery. And I move the different div and span at their good place. But, I need to get the width of the price span.
How could I do that? Firefox say that the element is Null...
I tried something like that:
var widthPrice = $(element).$(".btm span.price").width();
and many variations and it's not work.
Here is the code:
NOTA: Must work with Explorer 8; cause the problem came from IE 8. (we use relative positionning before...)
Thank you,
Martin
Here is the code:
- var productlisttable = $$('div#content-product-slider table.productlisttable');
var sliderWidth = 273 * productlisttable.length;
if (sliderWidth < window.getWidth())
{
var i = 0;
var multiplicator = 1.3;
$('scrollbar1').setStyle('display', 'none');
$each(productlisttable, function(element) {
i++;
var leftValue = window.getWidth() / 2 - sliderWidth / 2;
element.getElements('.img a').setStyle("position", "relative");
element.getElements('.img a').setStyle("left", leftValue);
element.getElements('.btm a').setStyle("position", "relative");
element.getElements('.btm a').setStyle("left", leftValue);
element.getElements('.btm img').setStyle("position", "relative");
element.getElements('.btm img').setStyle("left", leftValue);
element.getElements('.btm a img').setStyle("position", "static");
element.getElements('.btm a img').setStyle("left", 0);
element.getElements('.btm span.price').setStyle("position", "absolute");
//var leftPrice = (leftValue * (1.3 * (i * productlisttable.length)) );
if (i > 1)
{
multiplicator = multiplicator * 1.5;
}
var widthPrice = 5;
var leftPrice = (leftValue * multiplicator) + widthPrice;
//alert("multiplicator " + multiplicator + "\nproductlisttable.length " + productlisttable.length + "\nleftValue " + leftValue + "\nLeftPrice " + leftPrice);
element.getElements('.btm span.price').setStyle("left", leftPrice);
});
}