Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
185
rated 0 times [  188] [ 3]  / answers: 1 / hits: 15714  / 10 Years ago, wed, october 1, 2014, 12:00:00

Ok, maybe its a stupid question with a little bug, but I'm trying fix this and I can not:



    <style>
.pagar a {
width: 200px;
height: 85px;
display: block;
background-image: url('imagens/pagar.jpg');
background-repeat: no-repeat;

}
.pagar a:hover {
background-image: url('imagens/pagar-hover.jpg');
background-repeat: no-repeat; }
</style>

<script>
function clickado() {
document.getElementsByClassName('pagar')[0].style.backgroundImage = 'url(imagens/pagar-clickado.jpg)';
}
</script>


HTML:



<div class=pagar id=pagar ><a href=# onclick=clickado()></a></div>


The problem:



The .style.backgroundImage just does not change to imagens/pagar-clickado.jpg, the the path is correct, I do not get error in console and ('pagar')[0] is also correct too.


More From » css

 Answers
4

I think you wanted to target the a element inside the div.pagar.
You can do something like this:



HTML



<div class=pagar ><a href=# id=pagar onclick=clickado()></a></div>


Javascript



function clickado() {
document.getElementById('pagar').style.backgroundImage = 'url(imagens/pagar-clickado.jpg)';
}

[#69275] Monday, September 29, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
serena

Total Points: 488
Total Questions: 125
Total Answers: 114

Location: Estonia
Member since Wed, Jun 8, 2022
2 Years ago
;