Regular expression for getting HREF from footer

前端 未结 3 1454
梦如初夏
梦如初夏 2021-01-28 05:46

I have a requirement where I need to get the last HREF in the HTML code, means getting the HREF in the footer of the page.

Is there any direct regular expression for the

3条回答
  •  时光取名叫无心
    2021-01-28 06:43

    You could use plain JavaScript for this (if you don't need it to be a jQuery object):

    var links = document.links;
    var lastLink = links[links.length - 1];
    var lastHref = lastLink.href;
    alert(lastHref);
    

    JS Fiddle demo.

    Disclaimer: the above code only works using JavaScript; as HTML itself has no regex, or DOM manipulation, capacity. If you need to use a different technology please leave a comment or edit your question to include the relevant tags.

提交回复
热议问题