0

How to adjust size of all images to 400*300 in a html file keeping following conditions ?

  1. with a single javascript located at the top
  2. without any additional file like css
  3. there are no Ids for images at present

In other words, I am finding a javascript (blahblah part) of a form

<script>
...
blahblah
...
</script>

<img src="image/01.jpg">
<img src="image/02.jpg">
...
<img src="image/99.jpg">

which will get the same effect as following

<img src="image/01.jpg" width=400 height=300>
<img src="image/02.jpg" width=400 height=300>
...
<img src="image/99.jpg" width=400 height=300>
5
  • Why do you need your script at the top? Commented Sep 26, 2020 at 1:18
  • I am just studying javascript.. I just want to know it is possible in easy way. Thank you. Commented Sep 26, 2020 at 1:22
  • Use getElementsByTagName(). You will not need any IDs. Commented Sep 26, 2020 at 1:22
  • Your statement does not make any sense. Commented Sep 26, 2020 at 1:23
  • I think you should at least try to write code before asking us to do it for you. Commented Sep 26, 2020 at 1:28

1 Answer 1

1
window.addEventListener('DOMContentLoaded', (event) => document.querySelectorAll('img').forEach((img) => ([img.width, img.height] = [400, 300])), false);
Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad it worked out for your usecase. If it completely satisfy you, please accept the answer.

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.