[英]Trying to get width of element inside .each()
我正在嘗試在.each()函數中獲取元素的寬度,但是我遇到了根本不起作用的問題。
jQuery(document).ready(function($) {
$('.tooltip').each(function() {
var self = $(this);
var width = self.find("#testing").offsetWidth;
alert(width); //Returns undefined
$(this).find(".tooltip-icon").hover(function(){
self.find(".tooltip-text").show();
}, function () {
self.find(".tooltip-text").hide();
});
});
});
您正在同一行中使用jquery和javascript
做這個
var width = self.find("#testing").width(); // jquery. you should change the name of the `self` variable to another one
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.