iBadGamer iBadGamer - 4 months ago 9
jQuery Question

Attribute in dom but not usable in a jQuery selector

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 !

Kld Kld
Answer

You can try this code

var arr = $('*').filter(function () {
   return $(this).attr('data-propzone') === "true"; 
});
console.log(arr);
Comments