$(document).ready(function()
{
$('button').on('click', function()
{
$('.container').children().eq(1).append($('p.important').text());
});
});
<div class="container">
<p>1</p>
<p>2</p>
<button>Lawl, a button.</button>
<p>3</p>
<p class="important">Text to be copied</p>
</div>
I want to find the closest upper p tag to my button. For example, if I move button under <p>1</p>
, it should append values to it. If I move my button to bottom, it should add append values to <p>3</p>
.
Is it possible with my current HTML?