0

I can't get the children from the svg fragment pre-entered in the string. Need return content <g> element from source string; Example: has dom:

<svg>
   <g class="parent"> <rect ... /> </g>
<svg>
let strNewContent = '<g class="draggable-group" data-id-device="Light-X[room-1549613406671][0]">   <rect height="75" width="184" x="8" y="0" fill="#DDD" rx="6" ry="6" />  </g>'; // created svg string using handlebars.js
// need replace old content in new content
// need extrude `<rect ... /> & etc...` from string and put (innerSVG) 

$('.parent').html($(strNewContent).html()) // I understand it won't work. (It's just to understand what I mean.)

d3.select(svgElem).html(d3.select(svgElem).html()); // костыль для обновления svg документа

ps:Thank you for your patience and understanding for my English

need extrude <rect ... /> & etc... from string and put (innerSVG)

I understand that this can be done in 2 ways (as I can see): by a regular expression, cut the content or convert it to a fragment and try to squeeze out the content and add it to a new element as content (helped by @altocumulus). But I really already tried, many times to convert to a fragment and to squeeze out contents, nothing turns out (only now came to the decision, with a regular expression)(now I will experiment).

ps: What's best to correct (title) the issue for everyone to deal with this problem to solve it?

Vad0k
  • 325
  • 3
  • 13
  • 2
    Doesn't `d3.select(".parent").html(strNewContent).select("rect");` do what you want? See https://jsfiddle.net/vbjunfd8/1/ – altocumulus Feb 07 '19 at 17:13
  • Yes, Your code is working. I wrote a question last night and got a little typoed (understated). I can answer it as true. (I here is think create a new question or edit this a bit?) – Vad0k Feb 08 '19 at 08:07
  • @altocumulus, I apologize for wasting Your time by my mistake. – Vad0k Feb 08 '19 at 08:39
  • All-same decided to wrap in svg and to issue `d3.select ('.parent').html ($(\`${strNewContent}\`).find('.draggable-group').html() );` – Vad0k Feb 08 '19 at 08:52
  • 1
    Don't use jQuery to manipulate an SVG's DOM as it was designed for the HTML namespace and does not work well with SVG's namespace. Have a look at my [answer](https://stackoverflow.com/a/29805796/4235784) to [*"Style a d3 element with jQuery and CSS"*](/q/29805098) for more details. Why are you mixing in jQuery in the first place? You said that my first suggested solution did work, right? I am afraid, I don't really understand what you are after. – altocumulus Feb 08 '19 at 09:04

0 Answers0