The task is that I am trying to pass the resulting value in this case to the number 1 1 1, the data values ​​are contained in this line in the code $('#res').append(' '); then I try to pass this value to a function that accepts parameters and saves this value to a file, a line

 var csvData = 'data:application/csv;charset=utf-8,' + $('#res').append(' '); 


As soon as I insert the line $('#res').append(' ') the following [objectObject] is written to the file, but I make an error when I try to write on js and jquery in one place. Tell me how to make the values ​​1 1 1 which contains this line $('#res').append(' ') fall into the file

 function recalculate(){ $('#res').text(''); var sum = 0; $('div').each(function(){ var selectVal = $('select',this).val(); $('#res').append(selectVal); if($(this).index() < $('div').length - 1){ $('#res').append(' '); //содержит значения 1 1 1 } sum +=selectVal * 1; }); $('#res').append('<p>Согласовано: ' + sum + ' </p>'); document.getElementById('tfa_src_data').onclick = function() { var csv = JSON.stringify(localStorage['savedCoords']); var csvData = 'data:application/csv;charset=utf-8,' + $('#res').append(' '); this.href = csvData; this.target = '_blank'; this.download = 'filename.txt'; }}; 
  • What is the #res element? - Grundy
  • @Grundy. in html code it is <span id = "res"> </ span>, the result is displayed here. - Eliot

1 answer 1

The .append method returns a jQuery object, so when casting it to a string, we get [object Object]

To get the text / html from the span element, you can use the methods text / html

As a result, the line may look like this:

 var csvData = 'data:application/csv;charset=utf-8,' + $('#res').append(' ').text(); 
  • I thank for the answer, now the recording is correct. - Eliot