繁体   English   中英

尝试获取.each()中元素的宽度

[英]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.

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