Create Boot using Document.createelement()

Asked

Viewed 6,086 times

1

I really need a little help since grad school. I need to create this function:

<input type="button" value="Refresh Page" onClick="history.go(0)">

However it should be created using the method Document.createelement() and I’m not getting, already tried in several ways but I always end up with an empty input text box that does not serve for nothing and the button doesn’t even appear. If it is not possible to create this button, a written text AGAIN clickable to refresh also serves. I tried to do and the page is in eternal Reload even before it is loaded. Taking advantage of the question, in case I change the history.go(0) for history.go(-1) It goes back to the previous page? Thank you very much. To link

var ae = document.createElement('a');
var eText = document.createTextNode("AGAIN");
ae.appendChild(eText);
ae.title = "AGAIN";
ae.href = window.location.reload();
document.body.appendChild(ae);

Para Botao

    var batsu = document.createElement("input");  
    batsu.setAttribute('type', 'button');  
    batsu.setAttribute('valeu', 'AGAIN');  
    batsu.setAttribute('onClick', 'history.go(0)');  
    document.body.appendChild(batsu);

1 answer

0


To create a button with document.createElement, follow suit:

Button

function createButton()
{
     var btn = document.createElement('BUTTON');
     var lbl = document.createTextNode("CLICK ME");        
     btn.appendChild(lbl);   
     btn.onclick = function()
     {
        window.history.go(0);
     }
     document.body.appendChild(btn);    
}

createButton();

input type button

var batsu = document.createElement("input");  
    batsu.type = 'button';  
    batsu.value = 'AGAIN';  
    batsu.onclick = function() { window.history.go(0); };  
    document.body.appendChild(batsu);

References

  • Exactly what I was needing, thank you very much Virgilio and Lucas

  • @Kappa I did your way had problem in the code and now it works also take a look

  • 1

    AMAZING, I WAS BREAKING MY HEAD ON TIME ON THIS, THANK YOU VERY MUCH

Browser other questions tagged

You are not signed in. Login or sign up in order to post.