jQuery devuelve CSS abreviado para el atributo de estilo

Why is it that jQuery returns short hand CSS when I try the following:

alert($('#t1').attr('style'));

On this html:

<div id="t1" style="border-style: solid; border-width: 10px; border-color: red; height: 100px; width: 100px;">Hello</div>

Vuelve:

border: 10px solid red; height: 100px; width: 100px;

This happens in firefox. Not in chrome.

How can I get the contents of the style attribute exactly as it appears?

Aquí hay una complete test.

preguntado el 08 de noviembre de 11 a las 18:11

It's up to the browser how it returns that information. I doubt jQuery tries to parse/interpret the data. -

This may be browser dependent. In Chrome, I got the full style. -

It might be better to state what you plan to do with the style data after you retrieve it. What is the purpose? Perhaps we can assist. -

FYI: I'm getting the style as you declared ("border-style: solid; border-width: 10px; border-color: red; height: 100px; width: 100px;") in Firefox 7.0.1 -

I'm getting the style as you declared ("border-style: solid; border-width: 10px; border-color: red; height: 100px; width: 100px;") in Firefox 7.0.1 -

2 Respuestas

What do you want to do? Hard to see what you want.

That said, what happens if you use pure js, something like

(function getStyles(){
    var styles = document.getElementById("t1").getAttribute("style");
    alert(styles);
})();

Ejemplo: http://jsfiddle.net/5UJwF/2/

respondido 08 nov., 11:23

Just for clarification purposes, the conclusion is what has been suggested already - this is a browser interpretation and not a jQuery interpretation. So I've upgraded to FF 7.0 and it seems to work for me.

respondido 10 nov., 11:14

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.