I have a question about changing the width attribute of css <img> tag with javascript JavaScript

Asked 2 years ago, Updated 2 years ago, 107 views

window.onload=function() {
    var img = document.querySelector('img')
    var size=100;
    img.width=size;
    img.height=size;
    img.style.width=size + 'px';
    img.style.height=size + 'px';
}

Hello, I have a question from the above code.

img.width = number , img.style.width = number+'px' I know it's the same as a result, but

I'm just curious about the difference between the two. People around me say it's a useless question, but this is how the grammar works Can I think about it?

javascript css width img

2022-09-22 21:24

1 Answers

As you said, it doesn't seem to mean much to distinguish the difference between the two.

That's where we'll find meaning.


2022-09-22 21:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.