Click here to Skip to main content
15,888,802 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I need to get the style of an element and write it out. The problem is, the styles are given though multiple classes. Is there a way for me to see exactly what styles are influencing an element?

EDIT: Ok, I think the question is pretty self explanatory, but here:

<div id="myDiv" class="divClass">
<label class="labelClass">Hello World</label>
</div>


Lets say that the divClass has "width:250px", and the labelClass has "color:#e3e3e3". I need to get those styles through a JavaScript function.
Posted
Updated 1-Aug-11 21:31pm
v2
Comments
Monjurul Habib 2-Aug-11 3:27am    
clarify your question with examples.
RaisKazi 2-Aug-11 3:31am    
Do you want to check this by Programming Or in Browser by Tool?

firebug[^] will help you

Using javascript
Get the rendered style of an element[^]
 
Share this answer
 
Comments
DominicZA 2-Aug-11 3:45am    
I have Googled and found that exact page. The problem with that method is I will have to loop through every possible CSS attribute and see if it is applied.
Abhinav S 2-Aug-11 9:43am    
Good try. My 5.
Thanks for your question.



JavaScript
var omyDiv = document.getElementById('myDiv');
var class= omyDiv.style.className;


Thanks,
Mamun
 
Share this answer
 
v2
Comments
DominicZA 2-Aug-11 4:12am    
Thanks, but I am getting an "obj.style is undefined" error.
Abdul Quader Mamun 2-Aug-11 5:27am    
Lets check the source of your code. What is the name of your myDiv. And then use that Id from source code.
document.getElementById('myDiv').className


This will return you the applied class on the control.
 
Share this answer
 
Use firebug tool of mozilla and you can inspect element
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900