Reputation: 1367
I am trying to get a simple jquery function to work, but it just won't budge. I have several
<p id="actor_name">
with various values. Each is inside it's own <div class=result>
. The goal s to take the value of the clicked .result
div and append it to a textarea. I can't believe I am heaving trouble getting this to work. I even made a JSFIDDLE to separate it from the rest of my application and it still won't work.
The fiddle is here: JSFIDDLE.
The code is also below. I just hope it's not something like a missing semi con, so I don't make myself look so bad :/
html
<div class="found_actors">
<div class="result"><p id="actor_name">Actor Name1</p></div>
<div class="result"><p id="actor_name">Actor Name2</p></div>
<div class="result"><p id="actor_name">Actor Name3</p></div>
<div class="result"><p id="actor_name">Actor Name4</p></div>
<div class="result"><p id="actor_name">Actor Name5</p></div>
</div>
<textarea readonly="" style="resize: none;" rows="20" cols="20" name="actors"></textarea>
jQuery
$(".result").click(function() {
$("[name='actors']").append($("#actor_name").val());
});
Upvotes: 1
Views: 596
Reputation: 573
Id's are for unique elements, I also think what your looking for is the html of the p element and not the val() i leave you this fiddle http://jsfiddle.net/JNaS9/16/
$(".result").click(function() {
var text = $(this).find("p").text();
$("textarea").empty().append(text);
});
Upvotes: 0
Reputation: 35194
Don't use the same id on several p tags. I suppose this is what you're asking for:
$("[name='actors']").empty().append($(this).find('p').text());
Remove .empty()
if you don't want to clear the textarea on each click.
Upvotes: 3