0

I'm new to frontend development, and I want to rezize an <img> with JavaScript:

Which element?

<div class="dz-image">
 <img data-dz-thumbnail="" alt="principal.png" src="http://localhost:49407/file/Image/660">
</div>

What function im using in js?

this.emit("thumbnail", mockFile, "http://localhost:11111/file/Image/" + principal)
 { document.querySelector('data-dz-thumbnail') }; 

I'm using querySelector to get the spefic <img> element.

Is it possible to add some style directly on that line like height:120; width: 120;?

KyleMit
31.4k74 gold badges516 silver badges709 bronze badges
asked Apr 1, 2020 at 18:15
3
  • 1
    You have mentioned nothing about what issue are you having with current code? Also, what is this.emit & mockFile here? Commented Apr 1, 2020 at 18:17
  • 1
    I doubt if this itself works document.querySelector('data-dz-thumbnail') Commented Apr 1, 2020 at 18:18
  • This is working but i want to change size of the img. this (dropzone or drag and drop) has an event called emit when creates that div. mockfile is a simulated file on javascript based on a file stored on the server. Commented Apr 1, 2020 at 18:19

3 Answers 3

2

Yes,it is possible to add some style directly.

let ele = document.querySelector('[data-dz-thumbnail]')
ele.style.width="120px"
ele.style.height="120px"
answered Apr 1, 2020 at 18:32

3 Comments

It looks like the correct answer, however img size still the same. (im not sure if this is for another reason)
It is working for me. can host your code in jsfiddle or some where @gaccerboni
This fix my problem on the img but changes all the others that shouldnt: 'code' $('div.content img').css('width', '120'); $('div.content img').css('height', '120'); 'code'
1

Per my understanding, queryselector should be classname, id or tag

Second you can add css by taking a variable for your querySelector line. It is like:

var el = document.querySelector('div'); 
el.style.backgroundColor = 'green';
el.style.display = 'none';
el.style['border-radius'] = '5px';
KyleMit
31.4k74 gold badges516 silver badges709 bronze badges
answered Apr 1, 2020 at 18:26

Comments

0

I solved this using jQuery's .css() method like this:

$('[data-dz-thumbnail]').css('width', '120');
$('[data-dz-thumbnail]').css('height', '120');
KyleMit
31.4k74 gold badges516 silver badges709 bronze badges
answered Apr 1, 2020 at 18:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.