Query [HTML]

0

Good afternoon, I have a problem .. I'm just starting to see html and I'm following a little pdf. The problem is that I put two buttons, one to change the color and another to change the size. The first button works but the second does not.

function cambiarColor() 
{   var tit=document.getElementById('titulo');   
    tit.style.color='#ff0000'; } 
 
function cambiarTamanoFuente() 
{   var tit=document.getElementById('titulo');  
    tit.style.fontSize=1; }
<html> 
    <head> 
        <title>Problema</title> 
        <script src="funciones.js"></script> 
    </head> 
    <body> 
        <h1 id="titulo">Este es un titulo dinamico</h1>  
        <input type="button" value="Cambiar Color" onClick="cambiarColor()"> 
        <input type="button" value="Cambiar Color" onClick="cambiarTamanoFuente()"> 
    </body> 
</html> 

I hope you can help me. Greetings!

    
asked by facuk 03.11.2017 в 22:29
source

2 answers

1

It does not work for you because you forgot to concatenate the unit of measure (px) which is necessary to change sizes, you should do it like this:

function cambiarColor() 
{   var tit=document.getElementById('titulo');   
    tit.style.color='#ff0000'; } 
 
function cambiarTamanoFuente() 
{   var tit=document.getElementById('titulo');  
    tit.style.fontSize=1 + 'px'; }
<html> 
    <head> 
        <title>Problema</title> 
        <script src="funciones.js"></script> 
    </head> 
    <body> 
        <h1 id="titulo">Este es un titulo dinamico</h1>  
        <input type="button" value="Cambiar Color" onClick="cambiarColor()"> 
        <input type="button" value="Cambiar Color" onClick="cambiarTamanoFuente()"> 
    </body> 
</html> 
    
answered by 03.11.2017 / 22:31
source
1
function cambiarTamanoFuente() {
  var tit=document.getElementById('titulo');
  tit.style.fontSize='20px';
}
    
answered by 03.11.2017 в 22:32