Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

95
Views
background-blend-mode for SVG

I am create SVG element in JS like this:

 var svgElem = document.createElementNS(xmls,"svg");
 svgElem.setAttributeNS(null,"viewBox","0 0 500 500");
 svgElem.setAttributeNS(null,"width","500");
 svgElem.setAttributeNS(null,"height","500");
 svgElem.style.backgroundImage = "url(imageUrl)";
 svgElem.style.backgroundSize = "cover";

now I wanna set background-blend-mode: difference for SVG element in JS how I can do it?

also I wanna set filter to SVG element but do not work with

svgElem.style.filter = "hue-rotate(180deg) saturate(2)";
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can set the background-blend-mode in style attribute in the same way as you have set the other styles. But it needs something to blend with so this snippet gives it a background-color as well.

UPDATE: the question was expanded to include a requirement to add filter property as well. This snippet has been altered to include that and it seems to work fine.

var svgElem = document.createElementNS("http://www.w3.org/2000/svg", "svg");
svgElem.setAttributeNS(null, "viewBox", "0 0 500 500");
svgElem.setAttributeNS(null, "width", "500");
svgElem.setAttributeNS(null, "height", "500");
svgElem.style.backgroundImage = "url(https://i.stack.imgur.com/qCIve.jpg)";
svgElem.style.backgroundSize = "cover";
svgElem.style.backgroundColor = 'red';
svgElem.style.backgroundBlendMode = 'difference';
svgElem.style.filter = "hue-rotate(180deg) saturate(2)";
document.body.appendChild(svgElem);

Here's the original image:

enter image description here

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!