简体   繁体   English

我在dom中看到一个属性 <td> 元素,但无法在jQuery中检索到

[英]I see a attribute in dom <td> element, but unable to retrieve that in jQuery

I am trying to get the value width="25%" from <td valign="top" width="25%"> , I am starting from a descendant location way below the <td> . 我正在尝试从<td valign="top" width="25%">获得值width="25%" ,我是从<td>下方的子孙位置开始的。 Possibly there might be more <td> elements between my target <td valign="top" width="25%"> . 在我的目标<td valign="top" width="25%">之间可能可能有更多的<td>元素。 But I simply cannot get 25% from the below. 但我根本无法从下面获得25%的收益。

I have tried: 我努力了:

var prts = jQuery('.someClassWayBelow').parents('td');

jQuery.each (prts, function () { var css = prts.width(); console.log(css)});
jQuery.each (prts, function () { var css = prts.attr("width"); console.log(css)})

I get 664px or 664 or undefined , how do I get a return of 25% ? 我得到664px664undefined ,如何获得25%的回报?

Appreciate in advance. 提前欣赏。

 $(document).ready(function(){console.log($("div").attr('width')); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div width="25%"> </div> 

使用$ (this)将要考虑的元素制成jQuery对象后,便可以访问attr()方法

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

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