I have a code that clicks a button, but I want to do the same without jquery, since jquery makes my page very slow, how do I do it with javascript? this is the code:
<script src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
<script>
$(document).ready(function()
setTimeout(clickbutton,5000);
function clickbutton()
{
$("#botonEnviar").click();
}
});
</script>
I leave you this example, I hope it helps you orient yourself for your situation
I make use of a listener to listen when
DOM
it is "ready" throughDOMContentLoaded
and then call the functionsetTimeout
which inside receives the name of my custom function and the time allotted.Outside of reading the
DOM
, I develop my custom function, where withquerySelector()
I get the id of the HTML element I want to get.For example purposes with the innerHTML method I modify the content of the
button
to show the functionality of the newly created codeThere are many ways to do it, but I would like to point out that jQuery is a very lightweight library and I don't think it's jQuery that's slowing you down, maybe you're calling various css styles.
But to the question, how to do what you have without jQuery. The way I do it:
In the body (this causes the clickbutton function to be executed when the page is opened.
Then in the html of your button, suppose you have something like this
then your script