javascript - 如何从 html 中查找数据并使用 jQuery 存储它

标签 javascript jquery

我的 HTML

<div class="product">
 <img src="#">
  <div class="priceStore">
   <p data="40">Item 1</p>
 </div>
</div>

如何使用 jQuery 检索数据并存储它?

我的尝试:

$('.product').mousedown(function(event) {
    var x = $('.priceStore').parent().find(data);
    console.log(x);
});

谢谢!

最佳答案

有几种不同的方法来编写选择器,但要获取属性的值,您可以使用 .attr()

类似的东西适用于这种情况

$('.product').mousedown(function(event) {
    var x = $('.priceStore p').attr('data');
    console.log(x);
});

关于javascript - 如何从 html 中查找数据并使用 jQuery 存储它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34621933/

相关文章:

javascript - Draft.js 中的自定义可编程小部件(插件)

javascript - 使用 CommonJS 语法中的文件使用 Karma 和 RequireJS 进行测试

javascript - 尝试启动 Express 应用程序时出现奇怪的 Node.js 错误

javascript - 如何让按钮保存对本地存储所做的任何更改?

javascript - 按钮的 Jquery 选择器

javascript - Angularjs 中 ng-view 位置更改后突出显示文本

javascript - HTML5视频自定义控件: How to show the current frame of the video while dragging the seekbar

jquery - jquery ui 选项卡中取消选择选项卡上的事件

javascript - CoffeeScript:抑制 "ReferenceError"

javascript - 将我的 css 类引用为对象?