Search code examples
jquerytagstextareamarkupstrip

jQuery: copy contents, strip <p> tags, and create linebreaks


I've succesfully created a behavior that copies the contents of a div container into a textarea field:

$('a').click(function() {
    var contents = $('.content').html();
    $('textarea').val(contents);    
});

http://jsfiddle.net/foomarks/E5sPj/6/

However, I'm stumped on:

  1. How to strip the paragraph tags.
  2. How to create a single line break to denote where the paragraph tag would be stripped.

Any suggestions are appreciated!


Solution

  • Try this

    $('a').click(function() {
    
    var contents = $('.content').html();
    contents = contents.replace(/<p>(.*?)<\/p>/gi,"$1\n");
    $('textarea').val(contents);    
    
    });