简体   繁体   中英

Set image width and height with jquery

I upload an image with the ck editor. When i select and upload the file, the editor automatic write the image width and height.

If i dont write in to this two field manualy 100% and 100%, how can i edit this with jquery? With this code, it writes the width and height to 100%, but the ck editor add these features into style attr.

$('div.content img').attr('width', '100%');
$('div.content img').attr('height', '100%');

How can i modify the img-s style attr with jquery, and set width and height to 100%?

Thank you!

You can just use jQuery 's CSS -

$('div.content img').css({
   'width' : '100%',
   'height' : '100%'
});

http://api.jquery.com/css/

If you need to set the style attributes, you can use jQuery's .css():

$('div.content img').css('width', '100%');
$('div.content img').css('height', '100%');

See https://api.jquery.com/css/

Have you tried something like this:
$("div.content img").css("cssText", "width: 100% !important;");>
Using jQuery to create the css and using !important to force it to take change

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM