Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

174
Vistas
How can I not show the border lines before the output is executed?

I am trying to hide the border of my div style because I have a div id to be put in that style but the border is showing before I click the button to execute the div id by a button.

This is for one of my assignments. Everything works fine other than this design flaw I have.

I am a complete beginner so may seem like a dumb question.

<html>
    <head>
        <title>Old MacDonald Verse</title>
        <script type="text/javascript">
            function OldMacVerse(animal,sound)
            {
            
                 document.getElementById('outputDiv').innerHTML=
                '<p>Old Macdonald had a farm, E-I-E-I-O.<br>' +
                'And on that farm he had a ' + animal + ', E-I-E-I-O. <br>' +
                'With a ' + sound + '-' + sound + ' here, and a ' + sound + '-' + sound +
                ' there, <br>' + ' here a ' + sound + ', there a ' + sound + 
                ', everywhere a ' + sound + '-' + sound + '.<br>' + 
                'Old Macdonald had a farm, E-I-E-I-O.</p>';
                                                                                       
            }
        </script>

        <body> 
            <div style= "border: solid; margin: auto; width:350px; text-align: center;">
            <h1>Old MacDonald Verse</h1>
            <input type="button" value="Pig Verse"
            onclick="OldMacVerse('pig','oink');">
            <input type="button" value="Sheep Verse"
            onclick="OldMacVerse('sheep','baa');">
            <input type="button" value="Cow Verse"
            onclick="OldMacVerse('cow', 'moo');">
        </div>

            <br>

        <div style= "border: groove; margin: auto; width: 350px; text-align: center;">
        </div>
        <div id="outputDiv">
        </div>

    </body>
</head>
</html>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can create a class for your output div:

<style>
.myclass {
   border: groove;
}
</style>

And apply the class dynamically in your function:

function OldMacVerse(animal, sound) {
   // ...
   var element = document.getElementById("outputDiv");
   element.classList.add("myclass");
   // ...
}

And remove the style from the external div.

Complete code:

<html>

<head>
    <title>Old MacDonald Verse</title>

    <style>
        .myclass {
            border: groove;
        }
    </style>
</head>

<body>
    <div style="border: solid; margin: auto; width:350px; text-align: center;">
        <h1>Old MacDonald Verse</h1>
        <input type="button" value="Pig Verse" onclick="OldMacVerse('pig','oink');">
        <input type="button" value="Sheep Verse" onclick="OldMacVerse('sheep','baa');">
        <input type="button" value="Cow Verse" onclick="OldMacVerse('cow', 'moo');">
    </div>

    <br>

    <div style="margin: auto; width: 350px; text-align: center;">
    </div>
    <div id="outputDiv">
    </div>

    <script type="text/javascript">
        function OldMacVerse(animal, sound) {
            var element = document.getElementById("outputDiv");
            element.classList.add("myclass");

            element.innerHTML =
                '<p>Old Macdonald had a farm, E-I-E-I-O.<br>' +
                'And on that farm he had a ' + animal + ', E-I-E-I-O. <br>' +
                'With a ' + sound + '-' + sound + ' here, and a ' + sound + '-' + sound +
                ' there, <br>' + ' here a ' + sound + ', there a ' + sound +
                ', everywhere a ' + sound + '-' + sound + '.<br>' +
                'Old Macdonald had a farm, E-I-E-I-O.</p>';

        }
    </script>

</body>


</html>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda