Petros Kyriakou Petros Kyriakou - 7 months ago 9
Javascript Question

Textarea has mysterious whitespace

For some reason the textarea i am appending to using jquery creates white space.

javascript

$(document).ready(function(){
var artistName = $("#artist-name").text();
var songName = $("#song-title").text();
var prepopulated_tweet = "@Myrfriends @RndomPerson \"you'll love this track\" @" + artistName + " - " + songName + " #Rock #Pop #Soul Krilex.******.co/rx11"
$("#tweet-message").append(prepopulated_tweet);
})


html

<textarea name="name" rows="4" cols="80" id="tweet-message"></textarea>


output


@Myrfriends @RndomPerson "you'll love this track" @Krilex -

Pieces - Red

#Rock #Pop #Soul Krilex.*****.co/rx11


any clues?

Answer

Content in #song-title element must have new lines.

Given:

<div id="song-title">
  Pieces - Red
</div>

$("#song-title").text(); would return:

"
  Pieces - Red
"