jQuery equivalent of getting the context of a Canvas

前端 未结 4 986
情歌与酒
情歌与酒 2020-11-30 00:18

I have the following working code:

ctx = document.getElementById(\"canvas\").getContext(\'2d\');

Is there any way to re-write it to use

4条回答
  •  自闭症患者
    2020-11-30 00:40

    Try:

    $("#canvas")[0].getContext('2d');
    

    jQuery exposes the actual DOM element in numeric indexes, where you can perform normal JavaScript/DOM functions.

提交回复
热议问题