Access to canvas via JQuery



  • Read that access to the canvas is implemented through square brackets:

        var canvas = $("#canvas1")[0];
        var x = canvas.getContext("2d");
        x.fillRect(50, 40, 55, 55);
    
    /*var d = $("#div1");
    d.css("background-color", "blue");*/
    

    Why other elements, for example divI'm just saying, id
    And the canvas is added. [0]or I don't get access.



  • var jqObject = $("#canvas1");              // возвращается jQuery-объект
    var domElement = $("#canvas1")[0];         // возвращается DOM-элемент
    var x = domElement.getContext("2d");       // JS-метод для DOM-элемента
    jqObject.css("background-color", "blue")   // jQuery-метод jQuery-объекта
    x.fillRect(50, 40, 55, 55);
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2