I want to know if there’s a way I can use jQuery or javascript to determine, given an element, if its width is set by a css style (either inline, inherited or directly) or if its being determined by the size/length of its content.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
One idea comes to mind:
Store the element’s
.width()Remove all children of the element, move them elsewhere, or make them
display: noneCheck out the element’s
.width(). If it has changed, it depended on the content. If it has not changed, it was set using CSS.Restore the children’s
displayproperty or move them back if necessary.Here is a very primitive prototype that simply removes all the element’s content:
There’s one side-effect for block level elements: Since their width doesn’t depend on the content, the script will return “…did not depend….” even though the element may not have had an explicit width set in CSS as you require.