Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Hide a page link

I'm trying to figure out how to hide a page link within a page, if the linked page contain a class="archived"

any help would be appreciated

Thanks

Using Jquery

11 Answers

$(".archived").remove();

It depends on what you want to do with that link, you want just to hide it and then show it?

be more specific and I can help you just right away.

I just want to hide it. The page the links on has a class of "drilldown-results" if($(".drilldown-results").... remove this page "<a href="/mw/index.php5/Client_Platforms" title="Client Platforms">Client Platforms</a>" has the class archived

do I need to pre-load the page to the link before I can hide the link?

can you paste the code? or a link to the challenge?

How do I paste the code

every time when you want to put a comment, below says "Markdown Cheatsheet" there are the instructions.

Highlight the section of code you want to copy by clicking and dragging and then copy code from your text editor with ctrl-c on windows or cmd-c on Mac. Paste it here with either ctrl-v for windows, or cmd-v for Mac. You can also use right click to do these steps. You can format your code nicely by putting three backticks, followed by the name of the language, like html or js, followed by a new line, followed by your code, followed by a newline and then three more backticks. The markdown cheat sheet is below the comments t box and all you need to do is click it.

I made this small codepen for you. Let me know if this helps.

I copied this out of inspect element and had to delete a lot of sensitive content. This is the browse data page and div tags may be off. the href's are the targets to hide

<div class="drilldown-results">
<div class="mw-spcontent">

<p>Showing below up to <b>15</b> results starting with #<b>1</b>.
</p><p>View (previous 250  |  next 250) (<a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=20&amp;offset=0&amp;_cat=Standard" title="Show 20 results per page" class="mw-numlink">20</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=50&amp;offset=0&amp;_cat=Standard" title="Show 50 results per page" class="mw-numlink">50</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=100&amp;offset=0&amp;_cat=Standard" title="Show 100 results per page" class="mw-numlink">100</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=250&amp;offset=0&amp;_cat=Standard" title="Show 250 results per page" class="mw-numlink">250</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=500&amp;offset=0&amp;_cat=Standard" title="Show 500 results per page" class="mw-numlink">500</a>)</p>            
            <div style="float: left; width: 33%;">
                <h3> <span class="mw-headline" id="D">D</span></h3>
                <ul>
<li><a href="/mw/index.php5/Databases" title="Databases">Databases</a></li><li><a href="/mw/index.php5/Databases_-_Database_Administration" title="Databases - Database Administration">Databases - Database Administration</a></li><li><a href="/mw/index.php5/Databases_-_Database_Management_Systems" title="Databases - Database Management Systems">Databases - Database Management Systems</a></li><li><a href="/mw/index.php5/Databases_-_Database_Shared_Platform" title="Databases - Database Shared Platform">Databases - Database Shared Platform</a></li>               </ul>
                <h3> <span class="mw-headline" id="E">E</span></h3>
                <ul>
<li><a href="/mw/index.php5/Embeded_2" title="Embeded 2">Embeded 2</a></li>             </ul>
            </div> 
            <div style="float: left; width: 33%;">
                <h3> <span class="mw-headline" id="I">I</span></h3>
                <ul>
<li><a href="/mw/index.php5/Integration" title="Integration">Integration</a></li><li><a href="/mw/index.php5/Integration_-_Application_Integration_%26_SOA" title="Integration - Application Integration &amp; SOA">Integration - Application Integration &amp; SOA</a></li><li><a href="/mw/index.php5/Integration_-_Business_Process_Management" title="Integration - Business Process Management">Integration - Business Process Management</a></li><li><a href="/mw/index.php5/Integration_-_Data_Interchange" title="Integration - Data Interchange">Integration - Data Interchange</a></li><li><a href="/mw/index.php5/Integration_-_Secure_File_Exchange,_Managed_File_Transfer" title="Integration - Secure File Exchange, Managed File Transfer">Integration - Secure File Exchange, Managed File Transfer</a></li>                </ul>
            </div> 
<p><br style="clear: both;">
</p>
            <br style="clear: both">
<p>View (previous 250  |  next 250) (<a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=20&amp;offset=0&amp;_cat=Standard" title="Show 20 results per page" class="mw-numlink">20</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=50&amp;offset=0&amp;_cat=Standard" title="Show 50 results per page" class="mw-numlink">50</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=100&amp;offset=0&amp;_cat=Standard" title="Show 100 results per page" class="mw-numlink">100</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=250&amp;offset=0&amp;_cat=Standard" title="Show 250 results per page" class="mw-numlink">250</a> | <a href="/mw/index.php5?title=Special:BrowseData/Standard&amp;limit=500&amp;offset=0&amp;_cat=Standard" title="Show 500 results per page" class="mw-numlink">500</a>)</p></div>
            </div>

Anyway we can see the page with tags? This is just plain text. Also, you used single quotes instead of backticks to format your code. Also, checkout the code pen I made for you above your comment.

so the class "archived" does not show up on the page with class "drilldown-results" so the script does not work on the class "archived". How do I test the page on the link for that class?

I'm a bit confused what you mean here. Are you saying you have one page with class drilldown-results and that on the page links that are listed, one of those pages has the class archived ( and not the actual link ) ?

The actual link shows, however the linked page has a div added with the class "archived".

Is there any way you could just give the link on the first page that you want to hide the class archived ? Trying to select something based on a class on a different page that hasn't been loaded would take a lot of work. I wish I could be of more help, but without actually seeing the code, there is little I can offer.

Thanks for your help, I figured it would be complex. I will look for another way

No problem, try looking into AJAX to get the div class you want. You could also possibly look into (assuming you are using a database) creating a links table with a column that lists whether or not each link is archived. Then, depending on which other languages you are working with, you could hide links on a page depending on the links archived status in the database itself. AJAX functionality might be a bit easier to add on though and there is a new course for it.

This is Semantic MediaWiki, extension SemanticDrilldown and it is using a mySQL on the backend.

I have been going through the AJAX course