Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

jquery-inline-svg

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jquery-inline-svg

Replace SVG images with inline SVG element

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
83
decreased by-20.95%
Maintainers
1
Weekly downloads
 
Created
Source

jQuery Inline SVG

NPM Package Minified Size License: MIT

Takes an <img> with an SVG as its source and replace it with an inline <svg> so you can manipulate the style of it with CSS/JS etc.

Install

npm

npm install jquery-inline-svg

Manually

Download the dist/jquery-inline-svg.min.js and add it to your project.

Usage

<!-- Add some SVG `<img>` tags. -->
<img src="image-one.svg" data-inline-svg>
<img src="image-two.svg" data-inline-svg>

<!-- Include the `jquery-inline-svg` script on your page after `jQuery`. -->
<script src="jquery.min.js"></script>
<script src="jquery-inline-svg.min.js"></script>

<!-- Inline images. -->
<script>
  $('[data-inline-svg]').inlineSvg();
</script>

<!-- The `<img>` tags have now been replaced with the full SVG markup. -->

Or with ES2015 modules

import $ from 'jquery';
import 'jquery-inline-svg';

$('[data-inline-svg]').inlineSvg();

Events

svgInlined event will be fired on every <img> with inlined SVG element as argument

$('[data-inline-svg]').on('svgInlined', function (e, svgElement) {
    const $originalImage = $(this); // <-- original <img> will be removed from the DOM when this event handler function finished
    const $inlinedSvgElement = $(svgElement).addClass('is-loaded');
})

Requirements

This plugin requires jQuery 3

Reference

Inspired by inlineSvg from UIkit 2 https://github.com/uikit/uikit/blob/v2/master/src/js/core/utility.js#L267

Keywords

FAQs

Package last updated on 01 Mar 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc