Test Foro de elhacker.net SMF 2.1

Programación => Desarrollo Web => Mensaje iniciado por: SrTrp en 23 Diciembre 2017, 05:34 AM

Título: error Cannot read property 'style' of null
Publicado por: SrTrp en 23 Diciembre 2017, 05:34 AM
Porque me da error? si se supone que todo lo ejecute bien.. :/
Código (html4strict) [Seleccionar]

<button type="button" onclick="llamada()">Set the background image of div</button>
<div>
     <div id=bgc" class="c1" style="width:600px;background-image: url('assets/b1.png'); background-repeat: no-repeat;">
     <img class="caobj" src="assets/d5.png" width="400" height=300"/>
     </div>
</div>


Código (javascript) [Seleccionar]

function llamada(){
          document.getElementById("bgc").style.backgroundImage = "url('assets/h1.png')";
    }
       
Título: Re: error Cannot read property 'style' of null
Publicado por: engel lex en 23 Diciembre 2017, 05:41 AM
solo por el resaltado de colores que hace GeSHi lo deberías notar XD

Código (html4strict) [Seleccionar]
<div id=bgc" class="c1"

no abres comillas en id, pero si cierras
Título: Re: error Cannot read property 'style' of null
Publicado por: SrTrp en 26 Diciembre 2017, 00:41 AM
Lol cierto andaba algo distraido gracias!!