1
Good evening (good morning or good afternoon) to all!
I need a function that returns the value of a css property. Follow my code:
CSS:
.teste{
opacity: 0;
display: none;
}
Javascript:
function funcao(){
var elemento = document.getElementById("teste");
function css(el, estilo){
alert(document.defaultView.getComputedStyle(el, null).estilo);
}
css(elemento, "display");
}
However this returns "Undefined", so I did the function with only 1 parameter, below:
Javascript:
function funcao(){
var elemento = document.getElementById("teste");
function css(el){
alert(document.defaultView.getComputedStyle(el, null).display);
}
css(elemento);
}
In this case it returns "None". The problem is that I will need to fetch the value of various properties of various classes, so the css(el, style) function would be perfect (if it worked and returned the "None" in the example), so I could use, for example:
css(teste, display);
css(teste, visibility);
css(testeDois, display);
The css() function only has the "Alert" for me to test what it returns, in the end, when it is working it will not have the "Alert", it will just return the value of the class property
I thank you all, from now on, I hope I have managed to be clear on my problem
Thank you very much!!!
Thank you very much man, with square brackets gave it right, this is exactly what I wanted. Thank you very much!!! : D
– Helhpon
Nice this solution. I will use it.
– Lucas_Kunze