Search code examples
jqueryimagehtmlresizable

Picture's width to be placed inside < div >


While resizing the picture, I want the picture width added to < div id="w" >< /div >, I have tried the following, anyone can help? thank you:

<script>
$(document).ready(
function() {
    $( "#resizable" ).resizable({
         resize: select_function
    });
});
var select_function = function(event, ui)
{
    $("#w").text($( "#resizable" ).attr("width"));
};

</script>
 <div id="w">Test</div>
<img border="0" id="resizable" src="picture.png">

Solution

  • You don't have a width="" attribute.

    To get the actual width of the element, call $( "#resizable" ).width().