0

I can't read the values set by external css sheaths when using webkit.

$(document).ready(function() {
    var plate = $(document.createElement('div'))
            .css({'overflow': 'hidden',
                  'display': 'inline-block'})
            .attr('class', $(this).attr('class'))
            .addClass('bbFormerPlate');
    console.log(plate.css('paddingRight'));
    console.log(plate.css('paddingBottom'));
});

The console in Chrome shows nothing. Just an empty line. Firefox have no problem. Tested Safari (Windows) which doesn't work either with lead me to believe that it's webkit that's the problem.

I tried to add it to another element that was already positioned on the page to see if that made any difference.

 $(positionedElement).wrap(plate);

No change. Still doesn't work on Webkit, but does work on FF.

The style declaration:

.bbFormerPlate {
    padding: 2px 15px 2px 5px;
    font-size: 10px;
}

The style is actually applied to the element as it appears on the page, but the value can not be read by the script. I can't remember I've had this problem before.

Any help would be appreciated.

2
  • You're putting your console.logs outside the dom ready declaration, so you have a scope issue. The plate variable only exists inside that function. Commented Jul 26, 2012 at 16:32
  • Ah... My bad. They are actually inside the ready declaration. I accidently put it outside when I wrote the above example Commented Jul 26, 2012 at 16:42

1 Answer 1

1

In your example you didn't inserted the element inside the dom, check this (working)

$(document).ready(function() {
    var plate = $('<div></div>')
        .css({'overflow': 'hidden',
              'display': 'inline-block'})
        .attr('class', $(this).attr('class'))
        .addClass('bbFormerPlate');
        $('body').append(plate); // added this line

    console.log(plate.css('paddingRight'));
    console.log(plate.css('fontSize'));
});​

DEMO.

Sign up to request clarification or add additional context in comments.

2 Comments

I thought .wrap would do that. I'll so some more testing and get back to you
Working with .append() and .appendTo() works fine. I'll stick with that instead of banging my head with .wrap(). Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.