the html structure:
<div class="user_register border_y">
<div>
<span style="color:green;"> after two seconds then auto redirect </span><br><br>
<a href="http://example.com/down/test.html">if you don't want to wait you can click this。</a></div></div>
i want to use jquery to get: after two seconds then auto redirect to the a
label page. how should i do?
You don't even need jQuery; vanilla JS will work fine...
<a id="link" href="http://example.com">Go NOW!!!</a>
JS:
window.setTimeout(function() {
location.href = document.getElementsByClassName("user_register border_y")[0].getElementsByTagName("a")[0].href;
}, 2000);
getElementsByClassName
doesn't work in all browsers; so make sure you provide a fallback
Use setTimeout
:
setTimeout(function() {
window.location.href = $("a")[0].href;
}, 2000);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With