简体   繁体   中英

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.

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

do this

var width = self.find("#testing").width(); // jquery. you should change the name of the `self` variable to another one

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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