Tag:jquery
Article From:https://segmentfault.com/q/1010000012143636
Question:

html

<dd class="col-sm-11">
    <a href="http://beijing.example.com">Beijing < /a>< a href= "http://tianjin.example.com" > Tianjin < /a>< a href= "http://shanGhai.example.com "> Shanghai < /a>< a href= "http://chongqing.example.com" > Chongqing < /a></dd>

I want to extract all the links:

<script>
    $(function () {
        var hrefs = $('a').attr("href");
        console.log(hrefs);
    });

</script>

The browser console doesn’t show anything. How can I print it?

Answer 0:
 $('.col-sm-11 a').each(function(i,e){
                    console.log($(this).attr("href"))
                  });

Answer 1:

It should be a hit.
jqueryThe value of the first DOM will only be acquired when the DOM array is selected.
So go through the output.

Leave a Reply

Your email address will not be published. Required fields are marked *