var element = document.getElementById("myElement");
var width = element.offsetWidth;
console.log("Ширина элемента: " + width + "px");
var element = document.getElementById("myElement");
var width = element.clientWidth;
console.log("Ширина элемента: " + width + "px");
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.3/jquery.min.js"></script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 class="txt">Текст</h1>
</body>
<script>
console.log($(".txt").width());
</script>
</html>