D
D
Dima Pautov2015-04-01 21:56:10
SVG
Dima Pautov, 2015-04-01 21:56:10

Loading svg into a page from a directory?

Here is an example for uploading images.

$('button').click(function(){
    var idImg = $(this).data('icon');
    $('div').html('<img src="/images/ico/'+idImg+'.png">');
  });

and upload the desired image!
How to do this on svg, but you need to get the code of the svg file, not insert the path into the img tag, as above, but get the full svg code of the image and insert it into the block so that you can change this picture further!
A similar implementation is offered by evil-icons.io/. , but a fully svg sprite from a js file is inserted there (where it is stupidly already registered) and the inserted icons refer to symbols through id.
Is it possible to?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Rulev, 2015-04-02
@bootd

You can get the contents of the svg with an ajax request, create an element from this string and add it to the DOM.

$('button').click(function(){
  $.get("/some.svg", function(data) {
    var svgEl = $(data);
    $('div').empty().append(svgEl);
  }, 'text');
});

Example: https://dl.dropboxusercontent.com/u/10234425/toste...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question