Just set the property backgroundImage
, don’t forget that your value should always be 'url(exemplo.png)'
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button id="bcen" onclick="if(--this.textContent<=0) alert('You\'ve won!');" value="10">10</button>
<script>
//Fundo no corpo da página
document.body.style.backgroundImage = 'url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTNylMnVaVWb0dAzVvBOxf8BiyTGlS8WK_3UZ1l2G0Ut0WfFb_Y)';
document.getElementById("bcen").style.width = "300px"; //Size
document.getElementById("bcen").style.height = "300px"; //Size
document.getElementById('bcen').style.fontSize = "200px"; //size
document.getElementById('bcen').style.color = 'red'
document.getElementById('bcen').style.backgroundImage = 'url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQxcBMtRs4ePVWb1m3pTBeALxaO_jIDZMMeTccOW-F7rCN4krU)'; document.getElementById('bcen').style.backgroundColor = 'transparent';
document.getElementById('bcen').style.borderRadius = "50%";
document.getElementById('bcen').style.outline = "none";
</script>
</body>
</html>
A note, as you are making several changes in the same element is advisable to save the reference to that element in a variable, see how the code gets smaller, cleaner and simpler to understand:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<button id="bcen" onclick="if(--this.textContent<=0) alert('You\'ve won!');" value="10">10</button>
<script>
//Fundo no corpo da página
let body = document.body;
body.style.backgroundImage = 'url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTNylMnVaVWb0dAzVvBOxf8BiyTGlS8WK_3UZ1l2G0Ut0WfFb_Y)';
let btn = document.getElementById('bcen');
btn.style.width = "300px"; //Size
btn.style.height = "300px"; //Size
btn.style.fontSize = "200px"; //size
btn.style.color = 'red'
btn.style.backgroundImage = 'url(https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcQxcBMtRs4ePVWb1m3pTBeALxaO_jIDZMMeTccOW-F7rCN4krU)';
btn.style.backgroundColor = 'transparent';
btn.style.borderRadius = "50%";
btn.style.outline = "none";
</script>
</body>
</html>
Kind of?
– Woss
It didn’t work here buddy!
– 20 Buscar
Could you update the question with your attempt?
– Woss
Yes I got it from a look there!
– 20 Buscar
You can help me?
– 20 Buscar
? I updated my brother
– 20 Buscar