Talha Akbar
Talha Akbar

Reputation: 10030

Paste Function Not working for first time jquery

<script type="text/javascript">
$(document).ready( function() {
$(".editableContent").bind('paste', function() {
var value = $(this).text();
var string = value.replace(/(<([^>]+)>)/ig,"");
$(this).text(string);
});
});
</script>

Paste Function Does not work for first time but second time it works , why?

Upvotes: 1

Views: 879

Answers (1)

user1726343
user1726343

Reputation:

Looks like you're trying to remove markup from your editable div. Just use this:

$(".editableContent").on('paste', function() {
    var self = this;
    setTimeout(function() {
        $(self).find('*').remove();
        $(self).append('<br />')
    }, 0);
});

Here is a demonstration: http://jsfiddle.net/4jSNN/1/

Upvotes: 1

Related Questions