I’m trying to select the first link on a page after the page has completely loaded and redirect the page to the link on the first page.
I understand how to use a selector, but I’m stumped as to how I can pick up the first item after the page loads. I’m assuming once I have the value I could use
window.location = "http://www.google.com/"
To then take the user to proper page once I have the dynamic link’s value.
A selector with the
:firstpseudo-class selects the first matched element. For more information on selectors, check out jQuery’s excellent documentation.EDIT
Actually ran my code and noticed that it was returning an empty string. This was because it was picking up the first
atag which happened to not have anhrefattribute. I’ve changed the selector to only selectatags with anhrefattribute.