Daniel Williams Daniel Williams - 2 years ago 71
Javascript Question

Fetching attribute values from CSS classes

I know similar questions have been asked but I've not been able to find a solution that works.

Can someone suggest how I could fetch the value of the width attribute from the CSS class so I can write it to the div.

Happy to do this with jQuery is possible.

document.getElementById("myDiv").innerHTML = 'value of CSS width';

#myDiv {
width: 177px;
border: 1px solid red;

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div id="myDiv">Hello World!</div>

Answer Source

This article from the jQuery documentation may help you. http://api.jquery.com/css/


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download