Forum How do I...?

Setting element.style.clip in javascript?

jasongladish
I've attached an example that uses this to set the clip property on an element:

        function test () {
            var h = document.getElementById('header_img');
            // h.setAttribute('style', 'clip:rect(0px, 50px, 50px, 0px)');
            h.style.clip = 'rect(0px, 50px, 50px, 0px)';
        }


When I run this the image isn't clipped, but when I use the setAttribute line instead the image IS clipped.

I expected h.style.clip= to work but it didn't. Is there an issue with trying to set the clip css property through javascript?
  1. clipex11.html5.9 kB
    clip example
mikeday
This appears to be a bug in the CSS parser, we will investigate.
mikeday
This was indeed a bug in the way that values were parsed and serialised, we have fixed it in the latest builds. Thank you for letting us know! :D
jasongladish
Fantastic, thanks for the quick turnaround!