jquery - Get DIV width and height in javascript -


i'm trying div width , height user changes , submit number page. can't seem figure out how width , height though.

<script> $(function() {   $( "#set div" ).draggable({      stack: "#set div",     preventcollision: true,     containment: $('#main_content'),       stop: function(event, ui) {           var mydiv = document.getelementbyid("set");           var pos_x = ui.offset.left;           var pos_y = ui.offset.top;            var width = mydiv.style.width;        ----this doesn't work           var height = mydiv.style.height;      ----this doesn't work            var window_width = window.innerwidth;           var window_height = window.innerheight;           var need = ui.helper.data("need");            console.log(pos_x);           console.log(pos_y);           console.log(width);           console.log(window_width);           console.log(need);            //do ajax call server           $.ajax({               type: "post",               url: "updatecoords.php",               data: { x: pos_x, y: pos_y, need_id: need, width: width, height: height, window_width: window_width, window_height: window_height}             }).done(function( msg ) {               alert( "data saved: " + msg );             });         }   }); }); </script> 

what's proper way this?

since you're using jquery, can do:

var width;  if (need == 1) {    width = $("#web").width(); } else {    width = $("#set").width(); } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -