Skip to content

Instantly share code, notes, and snippets.

@headquarters
Last active December 28, 2018 13:58
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save headquarters/5876199 to your computer and use it in GitHub Desktop.
Save headquarters/5876199 to your computer and use it in GitHub Desktop.
Find the offending element causing a horizontal scrollbar at any screen width (requires jQuery).
var screenWidth = window.innerWidth;
var visibleElements = jQuery(":visible");
visibleElements.each(function(){
var $this = jQuery(this);
if($this.width() > screenWidth){
$this.css("border", "1px solid green");
console.log("Screen width is " + screenWidth + " and the following element is " + $this.width(), $this);
}
});
@manardella
Copy link

Excellent. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment