Попытка получить ширину элемента внутри.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();
});
});
});
1 ответ
Решение
Вы используете jquery и javascript в одной строке
сделай это
var width = self.find("#testing").width(); // jquery. you should change the name of the `self` variable to another one