Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript [Solved] Set div height to the img inside it’s height Re: [Solved] Set div height to the img inside it’s height

#80484
noahgelman
Participant

Got it :D although I feel bad that I just wasted some forum space but maybe this’ll help someone later. I changed css to just .width() and .height() and tossed in the variables. Easy peasy.

Code:
$(function() {
var $example = $(‘div#example’);

$(‘a.link’).click(function() {
$(this).siblings().clone().prependTo(‘#example’);

var imgWidth = $(‘#example img’).css(‘width’);
imgHeight = $(‘#example img’).css(‘height’);

$example.width(imgWidth);
$example.height(imgHeight);

});
});