Home » Jquery » jquery – CSS: get color from angular

jquery – CSS: get color from angular

Posted by: admin February 22, 2020 Leave a comment

Questions:

From jquery we can take the color from an element like this

$('#js-color-profile').find('.color-primary-50').css('color')

in angular 2+ is any workaround to get the hex color?

How to&Answer:

You can get it with vanilla js like this. The getPropertyValue is not necessary, but the getComputedStyle will return all css for the element, that’s why I wrote it there.

getComputedStyle(element, null).getPropertyValue('color')

or

getComputedStyle(element, null)['color']