0

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/

2
  • $.parseHTML(dv) will return array Commented Mar 28, 2016 at 7:31
  • alert($.parseHTML(dv)[0].style.width); Commented Mar 28, 2016 at 7:37

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.