-1

I am trying to set the width of the div equal to another div. I have been tried the various function as below but it is not working. Please help me, How I achieve the goal.

.myclass:before {
  width: $("div.mydivclass").width();
} 

$(".myclass:before").css('width', $("div.mydivclass").width());
Sidharth
  • 11
  • 4

2 Answers2

0

  $(document).ready(function(){
   var getDivWidth = $('.mydivclass').width(); 
   $('.myclass').css({'width':getDivWidth,'border':'solid 1px #000','padding':'20px','margin':'10px 0px 0px'});
  });
.mydivclass{
  padding: 20px;
  width: 200px;
  border: solid 1px #000;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="mydivclass">
   Div 1
 </div>
 <div class="myclass">
   same width
 </div>
Vishal_VE
  • 1,852
  • 1
  • 6
  • 9
-1

You can do this by using table. For eg:

HTML:-

<div class="resultPanel">
            <table class="table">
                <thead>
                  <tr>
                      <th colspan="3"><h3 class="title">Title</h3></th>
                  </tr>
                </thead>
                <tbody>
                <tr>
                    <td>data</td>                    
                    <td>data</td>
                    <td>data</td>
                </tr>
                <tr>
                    <td>data</td>                    
                    <td>data</td>
                    <td>data</td>
                </tr>
                </tbody>
            </table>        
 </div>

CSS:-

.resultPanel {
  overflow: auto;
  padding-top: 40px;
  padding-left: 10px;
  width: 500px;
}
.title {
  background-color: gray;
  line-height: 40px;
  padding-left: 10px;
  margin-top: 0px;
  margin-bottom: 20px;
    text-align: left;
}
.table{
    width:700px;
}