Tom Martin
Tom Martin

Reputation: 1227

Resizing canvas element in Javascript function

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

Upvotes: 0

Views: 52

Answers (1)

Harben
Harben

Reputation: 1856

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.

Upvotes: 1

Related Questions