3

I face a very weird situation here. For the context I'm using a modified version of this svg-edit fork and I needed to add custom html attributes (data-propzone="true"). But the weird thing is when I load my svg with the svg-edit "setSvgString" function, I can't use my attribute as a selector, you can see in the screenshot that I can use the element ID or even the fill value and it's working fine, it retrieve my element with my custom attribute but with $('[data-propzone="true"]') the result is empty... Javascript console

My element with my custom attribute is in the dom as you can see: enter image description here

I really don't know what could be wrong here, I always use data-attributes selectors and never had an issue.

I'm sorry you can't reproduce it in the demo page because I had to make a modification to allow custom attributes to be added so you can't reproduce this issue, I hope the screenshot will be enough, if someone as a lead to help me understand it will be a great help !

iBadGamer
  • 566
  • 6
  • 22
  • 5
    Did you read this [Do SVG docs support custom data- attributes?](http://stackoverflow.com/questions/15532371/do-svg-docs-support-custom-data-attributes) – jcubic Jul 08 '16 at 14:35
  • @jcubic The OP doesn't seem to be using the data- API, he has an attribute that's compatible with that API but he's not using the API itself to get the data, just a CSS attribute selector which should work in theory. – Robert Longson Jul 08 '16 at 14:41

2 Answers2

1

You can try this code

var arr = $('*').filter(function () {
   return $(this).attr('data-propzone') === "true"; 
});
console.log(arr);
Kld
  • 6,970
  • 3
  • 37
  • 50
  • It does not work. I adapted your code a little with $("*") instead of $(document).children() and you can see the issue here... http://i.imgur.com/wTWVx0Q.png If the attribute is added it is working fine – iBadGamer Jul 08 '16 at 15:00
0

What if you try like this $('*[data-propzone="true"]') ?

Ersian
  • 219
  • 2
  • 12
  • What is weird here is that if I add an attribute AFTER the svg is "loaded" in the editor, it's working. You can see it here: http://imgur.com/RogErdm – iBadGamer Jul 08 '16 at 14:45