Olá, estou com o seguinte problema, eu fiz em um site que estou desenvolvendo, um script que ao clicar em um link, ele chama uma função para aumentar a fonte do paragrafo(p), e outro link para diminuir a fonte.
Porém, a unica maneira que eu consegui colocar para funcionar foi generalizado, ou seja, toda vez que eu clico para aumentar ou diminuir o texto, a função esta aplicando em todos as tag 'p' da pagina, sendo que eu queria que aumentasse em um especifico 'ID'.
Abaixo segue a função:<script type="text/javascript"> var min=9; var max=14; function increaseFontSize() { var p = document.getElementsByTagName('p'); for(i=0;i<p.length;i++) { if(p[i].style.fontSize) { var s = parseInt(p[i].style.fontSize.replace("px","")); } else { var s = 12; } if(s!=max) { s += 1; } p[i].style.fontSize = s+"px" } } function decreaseFontSize() { var p = document.getElementsByTagName('p'); for(i=0;i<p.length;i++) { if(p[i].style.fontSize) { var s = parseInt(p[i].style.fontSize.replace("px","")); } else { var s = 12; } if(s!=min) { s -= 1; } p[i].style.fontSize = s+"px" } } </script>
Nesta linha 'var p = document.getElementsByTagName('p');', eu tentei trolar o getElementsByTagName para 'ById', porém não funcionou
gostaria de algum tipo de auxilio
quem pode ajudar obrigado !
Atenciosamente, Victor Hugo Marques
com jquery:
$(function(){ $("#btnIncrease").on("click", function(){ var currentSize = $("#idDoParagrafo").css("fontSize"); if(currentSize < 20) { $("#idDoParagrafo").css( "font-size", "+=1"); } }); $("#btnDecrease").on("click", function(){ var currentSize = $("#idDoParagrafo").css("fontSize"); if(currentSize > 10) { $("#idDoParagrafo").css( "font-size", "-=1"); } }); });