Hi I have a problem: I try to build a flexible and responsive picture in div solution in bs 3, as I started in 2017, but it workspartially that means as I refresh the page otherwise it doesn't. the picture doesn't follow the div width changing. the code: var h2 = $(".city01").width(); $(".city01").width(h2); $(".city01").height(h2); $(".imgsz").width(h2); $(".imgsz").height(h2); <!-- $(".city01").text($("#div11").width());--> //$(".city01").height(); /* if ($(".imgsz").width() < $(".imgsz").height()) { $(".imgsz").height(h2); } else { $(".imgsz").width(h2); (*/ $(window).resize(function(){ h2 = $(".city01").width(); //$(".city01").css({'height':(h11)+'px'}); $("#div11").text(" width : "+ $(".city01").width ()+ " height : "+ $(".city01").height()); /* if ($(".imgsz").width() < $(".imgsz").height()) { $(".imgsz").height(h11); } else { $(".imgsz").width(h11); } */ $(".city01").width(h2); $(".city01").height(h2); https://codepen.io/cfrank2000/pen/zYqEVBB $(".imgsz").width(h2); $(".imgsz").height(h2); }); Code (JavaScript):
It works pretty nicely without the javascript - see https://jsfiddle.net/itamer/35kb1ms4/2/ The code you have above - what listener are you using to call it? What's the trigger?
1) what makes layout any of JavaScript's business? 2) what makes layout any of JavaScript's business?!? Now I realize this is in fact only one point, bit it's such a colossal sticking point I thought it merited saying twice. 3) <!-- --> is NOT how you comment out code in JavaScript. 4) as @sarahk said, how / where are you calling this code? It would need to be run both at onload and at window.onresize I should think. That said, see points 1 and 2.