I am building a Chrome extension (and therefore can only use JavaScript) and I need to get the link that resides in the h2
with the heading2
class.
However, there are multiple h2
items with that class (not shown here), and I will not know what the link will point to, as it changes monthly.
In this example, the content of the header is "Think before you tweet". It will always be under another header that contains the words "Featured Topic."
What I am looking to get is the /think_before_you_tweet
from the href=
of that h2
item. It shows that I have already completed the topic underneath the h2
, but that will not always be the case.
Here is the code for the website:
<div class="chosen_for_you_section">
<div class="internal_container">
<h2 class="section_header"><img src="/public/s360/img/360-spinner.png" class="s360LogoHeader">Featured Topic <a href="#require_topic" class="fancybox"><i class="fa fa-info-circle"></i> <span class="infoTxt">Read about what to do</span></a></h2>
<article class="article_block masonry_item " data-article_id="431">
<div class="article_image">
<a href="/think_before_you_tweet"><img src="/thumb/public/media/nh/images/twitter_tweet_think_before_send.png?q=&h=278" /></a>
<i class="fa fa-check-square-o article_complete article_type_icon" title="Article"></i>
<div class="action_icons">
<span class="like "><a title="Favorite"><i class="fa fa-heart"></i></a></span>
</div>
</div>
<header>
<h2 class="heading2"><a href="/think_before_you_tweet">Think Before You Tweet!</a></h2>
<div class="article_required_complete">Congratulations, you've completed this required topic.</div>
<div class="category_blocks">
<p>
<a href="/content/category/Social+Media">Social Media</a>
</p>
</div>
</header>
</article>
<div class="focus_items">
<div class="home_side">
<p>
<img alt="" src="" style="width: 430px; height: 422px;" /><!-- I hid the img src here because it reveals some personal information and is not important -->
</p>
<p></p>
</div>
</div>
</div>
</div>
I can use jQuery in my extension, but I do not have any back-end capabilities.