1. HTML section
< div class = "Bg-color-two" ID = "Bg_color_two" onclick = "SETBG (This)" ></ div > < div class = "Bg-color-three" ID = "Bg_color_three" onclick = "SETBG (This)" ></ div >
2. CSS Section
. Bg-color-two{width:40px;Height:40px;Background-image:URL (811915c596d17e09d4f85bd7e80ccee7.jpg);background-size:40px 40px; }. Bg-color-three{width:40px;Height:40px;Background-image:URL (675aa3366a8cda46febf0053c82e4f27.jpeg);background-size:40px 40px; }
3. js section
function SETBG (Control) { //Google gets the style property var with the getComputedStyle (object, attr) method bgimage = getComputedStyle (document.getElementById (control.id), "style"). BackgroundImage; Console.log (bgimage//bgimage = "url (file:///C:/Users/Gladys/Desktop/ 811915c596d17e09d4f85bd7e80ccee7.jpg) }
Note: Both fire and Google Chrome can use the getComputedStyle (object, attr) method to get the style property, while Internet Explorer uses GetStyle (object, attr) to get the properties of the style
Get the Background-image value set in CSS in JS