0

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();
        });
    });
});
Daniel Vickers
  • 1,054
  • 1
  • 12
  • 32

1 Answers1

1

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
evgeni fotia
  • 4,650
  • 3
  • 16
  • 34
  • The jQuery option worked, however, please note that the javascript method does not as it returns the same error mentioned in my question. Will accept once able to. – Daniel Vickers Oct 18 '18 at 12:40
  • @DanielVickers Yes i forget that `self` is a jquery variable so the second way will not work – evgeni fotia Oct 18 '18 at 12:42