2016-06-21 7 views
0

ich will, wenn ich 1 Edit1 der Inhalt des Absatzes klicken Sie in Textfeld kopiert werden und wenn ich EDIT2 den Inhalt des Absatzes 2 Klicken kopiert werden zu

/*This is my jquery I am working with now*/ 
 

 
$(document).ready(function() { 
 
    $('.edit').click(function() { 
 
     var content = $('.paste').html(); 
 
     $('#area').html(content); 
 
    }); 
 
});
<!--This is my html code am using.. I want when I click Edit 1 the content of paragraph one is copied into my textarea and when I click Edit 2 link the paragraph is copied into textarea. The code now is working such that when I click Edit 2 the content of Edit 1 is copied in both cases...--> 
 
<div class="article"> 
 
    <p class="paste">Paragraph one </p> 
 
    <a href="#" class="edit">Edit 1</a> 
 
</div> 
 
<div class="article"> 
 
    <p class="paste">Paragraph two </p> 
 
    <a href="#" class="edit">Edit 2</a> 
 
</div> 
 
<textarea rows="5" class="form-control" placeholder="Enter text..." id="area"></textarea> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

Antwort

0
$(document).ready(function(){ 
    $('.article').find('.edit').on('click',function(event){ 
     event.preventDefault(); 
     var paraContent = event.target.parentNode.childNodes[1].textContent; 
     $('#area').val(content); 
    }); 
}); 

ich es geschafft haben, tief Online-Forschung und mit einer Antwort auf meine Frage kommen. Danke an jeden, der mir mit einer Antwort helfen wollte.