JointJS: Hello World example not working

I always see this exception when I try the Hello World example from the JointJS website:

Uncaught TypeError: Cannot call method 'getStrokeBBox' of undefined

Here is the code:

<!DOCTYPE html>
<html>
<head>
<!--
<link rel="stylesheet" href="css/joint.css" />
<script src="js/joint.js"></script>
-->


<link rel="stylesheet" type="text/css" href="http://www.jointjs.com/downloads/joint.css"></link>
<script type="text/javascript" src="http://www.jointjs.com/downloads/joint.js" ></script>


<script>
    var graph = new joint.dia.Graph;

    var paper = new joint.dia.Paper({
        el: $('#myholder'),
        width: 600,
        height: 200,
        model: graph
    });

    var rect = new joint.shapes.basic.Rect({
        position: { x: 100, y: 30 },
        size: { width: 100, height: 30 },
        attrs: { rect: { fill: 'blue' }, text: { text: 'my box', fill: 'white' } }
    });

    var rect2 = rect.clone();
    rect2.translate(300);

    var link = new joint.dia.Link({
        source: { id: rect.id },
        target: { id: rect2.id }
    });

    graph.addCells([rect, rect2, link]);
</script>
</head>
<title>Test</title>

<body>
    <div id="myholder"> </div>
</body>
</html>

I saw that another question has already been asked here on the same problem, but the solution given there does not matter, since I already have a div element for the paper object.

+4
source share
3 answers
el: $('#myholder'),

Browsers read from top to bottom. The browser executes this line before it finds an element with an identifier myholder, so it elis an empty jQuery object.

script HTML ( myholder, ) $(document).ready( .

+8

, . script <body> $(document).ready();

+1

not jQuery, :

window.onload = function () {   your entire javascript code here };

jQuery.js :

$(function () {  your entire javascript code here  });

, javascript, , " ". , , javascript, .

+1

Source: https://habr.com/ru/post/1527369/


All Articles