I try to get the height of <br />
on my webpage. I use this snippet.
br_size = $('br').height();
console.log(br_size);
But only the Mozilla Firefox
like this code, all other browsers give back 0.
Is there a short JS code that gives me the correct height back?
PS: i use this method, because i know that the needed size X
is X= other_size - 4*br_size
innerHeight() - Returns the height of an element (includes padding) outerWidth() - Returns the width of an element (includes padding and border) outerHeight() - Returns the height of an element (includes padding and border)
You can't change the height of <br> tag as its not an HTML element, it is just an instruction which enforces a line break. br does not take up any space in the page. There is a way by which you can increase line break between lines, is by putting multiple br tags.
Method 1: The height() method returns the first matched element's height, But the height(value) method sets all matched elements height. // Returns the height of the first matched element $(selector). height() // Set the height of the all matched elements $(selector). height(value);
jQuery outerWidth() and outerHeight() Methods The outerWidth() method returns the width of an element (includes padding and border). The outerHeight() method returns the height of an element (includes padding and border).
The line-break depends on the line-height specified in the HTML/BODY tags, if one isn't specified then the browser will likely use their own. However, if you specify a line-height, say 20px then the line-break should be 20px. You could probably use JavaScript to determine the default line-height
(function() {
var br = document.getElementById('foo');
alert(br.scrollHeight);
if (br.currentStyle) {
alert(br.currentStyle['lineHeight']);
} else {
alert(document.defaultView.getComputedStyle(br, null).getPropertyValue('line-height'));
}
})();
<br id="foo" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With