0

I have a JavaScript function that is passed a div tag that contains a canvas. I can locate the canvas and read the size of it but I cannot change the size of the canvas.

function ReSizeImage(item, Width, Height) {
    var canvas = item.find("canvas");
    canvas.each(function (i) {
        var CW = $(this).width(); //THIS GETS THE CORRECT VALUE
        $(this).width = Width //THIS DOES NOT WORK;

Any help much appreciated

1 Answer 1

1

jQuery Canvas Manipulation

There's a slight issue to your code, simple fix!

 function ReSizeImage(item, Width, Height) {
 var canvas = item.find("canvas");
 canvas.each(function (i) {
    var CW = $(this).width(); //THIS GETS THE CORRECT VALUE
    $(this)[0].width = Width //THIS DOES NOT WORK;

$(this) will be getting you a jQuery object and not a DOM element.

Sign up to request clarification or add additional context in comments.

2 Comments

$(this)[0].width = Width; can also be replaced with $(this).width(Width);
@Harben, sure i only mentioned it because i thought author accidentally wrote $(this).width = Width insteed of $(this).width(Width) as all code is written with jquery.

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.