I have a task to copy the content from a div into a textarea, allow for editing within the textarea, and ensure that any changes made are saved back to the original div.
I also need to filter out an attribute, such as data-bind: "some stuff;"
, set for the children of the main wrapper div, and comments so that they do not appear in the textarea.
So far, this is what I have, but I am struggling to figure out how to exclude specific text when extracting the HTML. https://jsfiddle.net/2kduy9vp/112/
$('.editor').html($('.main').html());
$('.editor').on('input propertychange', function(){
$('.main').html($(this).val());
});
.editor {
width: 100%;
height: 500px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="main">
<!-- I'm a comment, don't copy me -->
<div class="child" data-bind="don't copy me" style="background-color: gray; width: 250px;">
<span> I'm gray, copy me</span>
</div>
<!-- I'm a comment, don't copy me -->
<div class="child" data-bind="don't copy me" style="background-color: pink; width: 250px;">
<span> I'm pink, copy me</span>
</div>
</div>
<textarea class="editor"></textarea>