I'm making a little script using jQuery to send a sentence to a textarea by clicking on the text.
It does this fine however, if I edit the textarea to remove a sentence manually, I can no longer click on the sentences to send them to the textarea. Don't know why this happens. It's been a while since I played around with JavaScript.

I've tried to google this but cannot seem to find an answer. Does anybody have an answer for this? Or could you perhaps point me in the right direction to find the answer?

Many thanks guys,
Marauder

<!doctype html>
<html>
<head>
<link rel="stylesheet" href="1047803.css" type="text/css" />
<script type="text/javascript" src="jquery-1.6.4.js"></script>
<script type="text/javascript">

$(document).ready(function(){
  $("p").click(function(){

var testy = $(this).text();
$('#area51').append(testy + '\n');
  
  });
});
</script>
</head>
<body>
<div id="pagewidth" >
	<div id="wrapper" class="clearfix">
			<div id="maincol"></br></br></br>
				<textarea rows="15" cols="50" id="area51"></textarea>
			</div>

		<div id="leftcol"><h4>Sentence Examples</h4></br><center>
			<p>Example sentence 4</p>
			<p>Example sentence 4</p>
			<p>Example sentence 4</p>
			<p>Example sentence 4</p>
			</center>
		</div>

	</div>
</div>
</body>
</html>
<script type="text/javascript">

$(document).ready(function(){
  $("p").click(function(){

var testy = $(this).text();
var testAreContent = $('#area51').val();
testAreContent = testAreContent+testy + '\n';
$('#area51').val(testAreContent);
  
  });
});
</script>

Hi,

A small change in the jquery script.
This works fine.

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.