JavaScript instance Tutorial: Width and Style.width

Source: Internet
Author: User
Tags object numeric numeric value string

Article Introduction: today in writing a change to the picture width of the demo encountered a problem, I passed the image object, directly set the property image.style.width=100, not effective, and then find out why, because the Style.width received as a string, Image.width=100, this kind of writing is OK, because the width itself is number type.

Today in writing a change to the picture width of the demo encountered a problem, I passed the image object, directly set the property image.style.width=100, not effective, and then find out why, because the Style.width received as a string, Image.width=100, this kind of writing is OK, because the width itself is number type.

And then see a set of values about the Style.width, as follows

Ie
Id.style.width = "100"; With numeric value only, no error
Id.style.width = "100px"; With values and units, no errors
Id.style.width = "100px;"; With values, units, and semicolons, an error occurs

Ff
Id.style.width = "100"; With only numeric values, there will be an error
Id.style.width = "100px"; With values and units, no errors
Id.style.width = "100px;"; With values, units, and semicolons, no errors

So we usually write, it is best to use the "number + units" of this type of writing, in order to avoid unexpected errors.



Related Article

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.