How do I hide an svg:image when onerror is fired?
node.append('svg:image')
.attr("x", "-30px")
.attr("y", "-40px")
.attr("width", "60px")
.attr("height", "80px")
.attr("xlink:href", function(d){
return 'https://somedomain.com/images/' + d.name;
})
.attr("onerror", function(d){
console.log('The image ' + d.name + ' failed to load');
// this.style("visibility", "hidden");
// d.style("visibility", "hidden");
});
Based on your description, the code would look something like this:
.on("error", function() {
d3.select(this).style("visibility", "hidden");
});
That is assuming that the element you want to hide fires error events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With