简体   繁体   中英

JQuery .width() doesn't change the width

I have got two divs, one img and one video, which adjusts to the size of the screen automatically. I want my image to be the same width with the video and found this code on the web ( .you is the video and .santa is the image):

<script> 
    $( window ).resize(function() {
        $(".santa").width($(".you").width());
    });            
</script>

It does not change the width though.

It changes the width I wrote an example here for you, to check it just resize the page splitter

<div class="santa" style="width:100px;background-color:red">
santa
  <div class="you" style="width:200px;background-color:green">
    you
  </div>
</div>

$( window ).resize(function() {
  $(".santa").width($(".you").width());
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM