var content = $(this).html();
will return you the raw HTML
However, var content = $(this).text();
will return you just the text (minus the tags). Give that a shot.
문제
I'm using jQuery to get the content of a div element and then add that content into a textarea on click using:
$('.editBody').one('click', function() {
$(this).removeClass('two-columns');
$(this).removeClass('editBody');
var content = $(this).html();
var page = $(this).data('page');
var area = $(this).data('area');
$(this).html('<form name="editTagline" method="POST" action="editcontent.php">' +
'<input type="hidden" name="area" value="'+ area +'" />' +
'<input type="hidden" name="page" value="'+ page +'" />' +
'<textarea type="text" name="content" class="editBodytextarea">' + content + '</textarea>' +
'<button id="submit">Save</button></form>');
});
However, the textfield contains <p>
tags. I have tried using content.find("p").remove();
however this just breaks and doesn't output the textarea, just the paragraphs with <p>
tags.. Any ideas how to solve this?
Thanks in advance.
해결책
var content = $(this).html();
will return you the raw HTML
However, var content = $(this).text();
will return you just the text (minus the tags). Give that a shot.