Get html code from textarea (editor) and play with jquery functions and javascript while putting that content in DOM.

Add html in DOM without putting it in actual code (Dom in fly) using jQuery.

$(document).ready(function () {

	var full_story = $('#fulltext').val();
                                                                                                 
	var tempDiv = $('<div id="tempDiv">' + full_story + '</div>');
	outerHTML = tempDiv.find('.img-gal-box').clone().wrap('<p>').parent().html();

	if (outerHTML != undefined && outerHTML != '') {

		$('#txt_body').text(outerHTML);
		tempDiv.find('.img-gal-box').each(function (index, value) {

		    $(this).before('{img-gallery}');
		    $(this).remove();
		});

		$('#fulltext').val(tempDiv.html());
	}
});
 

 

Add html code in DOM by putting it in actual html code in runtime.

$('body').append('<div id="temp_div" style="display:none;"></div>');
$('#temp_div').html(full_story);

var outerHTML = $('#temp_div').find('.img-gal-box').clone().wrap('<p>').parent().html();

if (outerHTML != undefined && outerHTML != '') {
    
    $('#txt_body').text(outerHTML);
    $('#temp_div').find('.img-gal-box').each(function (index, value) {

            $(this).before('{img-gallery}');
            $(this).remove();
    });
    
    $('#fulltext').val($('#temp_div').html());                                    
}
$('#temp_div').remove();

 

  • JavaScript
  • js-dom
  • HTML