Reputation: 1272
I'm trying to build a list of emails from a webpage that is formatted like so:
<div class="somediv">
<div class="email-popdown">
<a href="mailto:[email protected]">[email protected]</a>
</div>
</div>
<div class="somediv">
<div class="email-popdown">
<a href="mailto:[email protected]">[email protected]</a>
</div>
</div>
<div class="somediv">
<div class="email-popdown">
<a href="mailto:[email protected]">[email protected]</a>
</div>
</div>
Here is my javascript that isn't working:
$('.email-popdown').each(function(i, obj) {
$('body').append($(this).child('a').attr('href') + '<br>');
});
Any help getting this to list emails as:
[email protected]
<br>
[email protected]
<br>
[email protected]
Thanks!
Upvotes: 1
Views: 34
Reputation: 25527
Use find() instead of child()
$('.email-popdown').each(function(i, obj) {
$('body').append($(this).find('a').text() + '<br>');
});
Upvotes: 1
Reputation: 36703
Use .find() instead of .child, and .replace("mailto:", "")
to strip of mailto:
from href
.
$('.email-popdown').each(function(i, obj) {
$('body').append($(this).find('a').attr('href').replace("mailto:", "") + '<br>');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="somediv">
<div class="email-popdown">
<a href="mailto:[email protected]">[email protected]</a>
</div>
</div>
<div class="somediv">
<div class="email-popdown">
<a href="mailto:[email protected]">[email protected]</a>
</div>
</div>
<div class="somediv">
<div class="email-popdown">
<a href="mailto:[email protected]">[email protected]</a>
</div>
</div>
Upvotes: 1