0

why this is not working?

<script>    
$('#draggable3').load(function() {
 alert($("#draggable3").width());
 $("#containment-wrapper").width() = $("#draggable3").width() * 1.3;
 $("#containment-wrapper").height() = $("#draggable3").height() * 1.3;

});
</script>
<body>
<div id="containment-wrapper">
<div id="border-ornament"> 

<img id="draggable3" class="draggable ui-widget-content" src="img.jpg">

</div>
</div>
</body>

why event .load not working after image is loaded?

tshepang
  • 10,772
  • 21
  • 84
  • 127
Dima Deplov
  • 3,538
  • 6
  • 41
  • 73

2 Answers2

2

Write width and height as -

$("#containment-wrapper").width($("#draggable3").width() * 1.3);
$("#containment-wrapper").height($("#draggable3").height() * 1.3);

and you need to write jquery in document.ready -

<script> 
$(document).ready(function(){
  $('#draggable3').load(function() {
     alert($("#draggable3").width());
     $("#containment-wrapper").width($("#draggable3").width() * 1.3);
     $("#containment-wrapper").height($("#draggable3").height() * 1.3);
  });
});   
</script>
Dipak
  • 11,154
  • 1
  • 27
  • 30
2

At the time of the script working tag #draggable3 not yet exists. Try do this in document.ready function like this

$(function () {
    $('#draggable3').load(function() {
     alert($("#draggable3").width());
     $("#containment-wrapper").width() = $("#draggable3").width() * 1.3;
     $("#containment-wrapper").height() = $("#draggable3").height() * 1.3;

    });
});

Or you can put your script after your img tag.

Nikita U.
  • 3,073
  • 1
  • 23
  • 32