There are three blocks that are in the workspace.
One of them is textual and has a width: auto;
How to determine its width and width of the workspace through JS?

  • $ ("div"). css ("width"); - C.Raf.T
  • And then how to use this value? For example, 1000 minus the width (received) and insert as the value left of another block? - bakusite 8:25 pm

1 answer 1

The simplest version on pure JS looks like this:

var width = document.getElementById('foo').offsetWidth; 

If you use the jQuery library, the code will be a bit simpler:

 var width = $('#foo').width(); 
  • And then how to use this value? For example, 1000 minus the width (received) and insert as the value left of another block? - bakusite
  • one
    Suppose the id of another block is "bar", and ours is with a width of "foo". Then $ ("# bar"). Css ('left', 1000 - $ ("# foo"). Width ()); - Ivan Pshenitsyn