简体   繁体   English

jQuery获取div的值并显示给其他div

[英]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. 我试图找出一种方法来获取div类的值,然后通过某种方式附加该值在另一个div中使用。

So say I click on product-item small below. 所以说我点击下面的小产品项。 I want item 1 to display in the p class of "added-item" 我希望项目1显示在“添加项目”的p类中

https://jsfiddle.net/jmy8fqqx/ 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 jQuery的

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

  });

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);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM