Search code examples
javascriptcssellipsis

Importing extern javascript (clamp.js) for line clamping not working


I want to clamp long texts with Clamp.js (https://github.com/josephschmitt/Clamp.js) but it is not working.

I only know a bit of JavaScript so there is probably some trivial misconception.

<head>
    <script type="text/javascript" src="https://github.com/josephschmitt/Clamp.js/blob/master/clamp.js"></script>
</head>

<body>
    <div style="height: 200px; width: 200px; background-color: aqua">
        <p id="test">super long text</p>
    </div>

    <script>
        var paragraph = document.getElementById("test");
        $clamp(paragraph, { clamp: 3 });
    </script>
</body>

</html>

expected: three lines of text + ellipsis

result: nothing


Solution

  • <head>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/Clamp.js/0.5.1/clamp.min.js"></script>
    </head>
    

    The only thing that I've change and it works for me.