Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

180
Visualizações
JS - added a button but need help to set his position

I'm trying to add a button with JS to HTML div tag, after adding it I would like to set his position to the right corner:

enter image description here

But when I added margin-left it dropped down a line.

How can I fix this?

the code:

function CheckForm(){
    let form = document.getElementById('fcf-form-id');
    if (form['Email'].value == "") {
        let x = document.getElementById('error-msg');
        const button = document.createElement('BUTTON');
        button.innerHTML = 'X';
        x.innerHTML = "I need you to enter you Email in order to get back to you."
        x.appendChild(button);
        button.style.marginLeft ='95%';
        x.setAttribute("style" , "opacity:1");
        button.addEventListener('click' , () => {  x.innerHTML ="";  x.setAttribute("style" , "opacity:0");    } )
        return false;
    }
about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Set the wrapper to be relative, set the button to be absolute and set the top and left.

.error {
  position: relative;
  background-color: yellow;
  border: 1px solid black;
}

.error .message {
  padding-left: 1em;
}

.error .close {
  position: absolute;
  top: 0;
  right: 0;
}
<div class="error">
<p class="message">
Hello World. It is foo.
</p>
<button class="close">x</close>
</div>

about 4 years ago · Santiago Trujillo Relatório

0

Can you share the code for this. You should ensure you use a reliable scaling ratio like % and you may way to set the display attribute of the button to inline-block

 display: inline-block;
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda