element offsetwidth calulation with empty space

Discussion in 'JavaScript' started by arthikbabu, Nov 25, 2009.

  1. #1
    Hi,
    I am not able to calculate the offsetwidth of the element which contains extra space in between the characters.

    for ex.
    if the element contains "A A" as a innerHTML value - if we calculate offsetwidth as 29 and also if the element contains "A A" value again I am getting the same offsetwidth as 29.

    While calculating the offsetwidth it is not calculating the empty space.

    May I know how to calculate the offsetwidth with the empty space because I need to insert the ellipsis (...) if it exceeds original width?


    Code snipet
    function fitStringToWidth(title,width,className) {
    var span = document.createElement("span");
    span.className="titleBar-Title-1";
    span.style.display='inline';
    span.style.visibility = 'hidden';
    span.style.padding = '0px';
    document.body.appendChild(span);
    var result = title;
    span.innerHTML = result;
    alert("Offsetwidth : " + span.offsetWidth);

    ..........................

    }


    Thanks in advance.

    Arthik
     
    arthikbabu, Nov 25, 2009 IP