StackUnderFlow StackUnderFlow - 1 month ago 7
Javascript Question

jQuery to get value of div and display to other div

I'm trying to figure out a way to get the value of a div class and then use that value in another div by appending it somehow.

So say I click on product-item small below. I want item 1 to display in the p class of "added-item"

https://jsfiddle.net/jmy8fqqx/

<a href="#" class="purchase"><span class="product-item small">item 1</span></a>
<a href="#" class="purchase"><span class="product-item medium">item 2</span></a>
<a href="#" class="purchase"><span class="product-item big">item 3</span></a>


<div class="bought">
<p class="added-item">
<!-- content will be loaded using jQuery - according to the selected item -->
</p>
</div>


Jquery

$( ".purchase" ).click(function() {

});

Answer

This should work for you. Please next time give some code you have tried.

$( ".purchase" ).click(function() {
    var item = $(this).find('span').html();
    $('p.added-item').html(item);
});
Comments