Skip to content

Instantly share code, notes, and snippets.

@directionforward
Last active March 13, 2020 16:23
Show Gist options
  • Save directionforward/57390e9ff5da42c019e6d54a99b4fa2e to your computer and use it in GitHub Desktop.
Save directionforward/57390e9ff5da42c019e6d54a99b4fa2e to your computer and use it in GitHub Desktop.
jQuery function to get width and height of SVG elements
/*
* .widthSVG(className)
* Get the current computed width for the first element in the set of matched SVG elements.
*/
$.fn.widthSVG = function(){
return ($(this).get(0)) ? $(this).get(0).getBBox().width : null;
};
/*
* .heightSVG(className)
* Get the current computed height for the first element in the set of matched SVG elements.
*/
$.fn.heightSVG = function(){
return ($(this).get(0)) ? $(this).get(0).getBBox().height : null;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment