Fergoso
Fergoso

Reputation: 1582

Specify dimensions for canvas element in jQuery

See below code. How do I specify a width and height within these lines?

Specifying a width and height using css does not work.

wrapper.append(
            $('<canvas />', { class: 'canvasClass', id: 'cElement' })
        );

Upvotes: 2

Views: 44

Answers (2)

Jatinder Kumar
Jatinder Kumar

Reputation: 513

You can also use below code:

$('.canvasClass').width(500).height(300);

Upvotes: 1

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

since canvas accepts width and height attribute

Try to use,

wrapper.append(
  $('<canvas />', { class: 'canvasClass', id: 'cElement' ,width:200, height:200 })
);

Upvotes: 3

Related Questions