简体   繁体   English

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

[英]Trying to get width of element inside .each()

I am trying to get the width of an element whilst inside a .each() function however I am running into issues with it simply not working. 我正在尝试在.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();
        });
    });
});

you are using jquery and javascript in the same line 您正在同一行中使用jquery和javascript

do this 做这个

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