Get width of string element without appending

Element:

var dv = "<div style='width:300px;height:100px'></div>";

How to I get 300px printed in the output?

alert($.parseHTML(dv).width()) //outputs undefined.

Fiddle: https://jsfiddle.net/3yq1bgvk/1/

Answers 1

  • You should create DOM element, instead of using $.parseHTML

    Use

    var dv = "<div style='width:300px;height:100px'></div>";
    alert($(dv).width());   //300
    

    jsFiddle


Related Articles