madapaja / jquery.selection

selection text/caret operation - jQuery pulgin | 選択範囲のテキスト操作 / キャレット操作
http://madapaja.github.com/jquery.selection/
191 stars 38 forks source link

Uncaught TypeError: Cannot read property 'substr' of undefined #9

Open onet4 opened 8 years ago

onet4 commented 8 years ago

Hi, looks like a nice plugin.

It seems this plugin cannot modify normal html text.

When you select words in the following example, you get an error, Uncaught TypeError: Cannot read property 'substr' of undefined.

<html>
<head>
    <meta charset="UTF-8">
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.0.min.js"></script>
    <script type="text/javascript" src="src/jquery.selection.js"></script>

</head>

<body>

    <div class="content">

        <p id="laten-text">Far far away, behind the word mountains, far from the countries Vokalia and Consonantia, there live the blind texts.</p>

    </div>

    <script>

        $( document ).ready( function() {

            $( '.content p' ).click(function(){                           
                $( this )
                    .selection('insert', {text: '<strong>', mode: 'before'})
                    .selection('insert', {text: '</strong>', mode: 'after'});

            });

        });

    </script>

</body>
</html>