Search code examples
javascriptjqueryhtmljsonstringify

JSON.stringify adding \n to the array


Why \n is appending to the value after JSON.stringify. Here is the example link

http://jsfiddle.net/7nketLmy/

 var formData = new Array();
 if ($(this).get(0).tagName.toUpperCase() === 'DIV' ){
        content = $(this).html();
    } 
 alert(JSON.stringify(formData));

Note: Content in the Div is dynamic and I don't have any control on what is displaying there. I should use .html() to get the data in Div


Solution

  • You added a new line in your div. that's why /n appearing

    <div contenteditable="true" placeholder=""  name="content[0]" id="pres_preview_58c57bd0044aa58704f13133b381e97a_0" class="pdfElement tempContent txtfield">Empire City Casino at Yonkers Raceway</div>
    

    Use like this.