Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 983623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:53:15+00:00 2026-05-16T04:53:15+00:00

I’m trying to write a greasemonkey script that only displays photos with the tags

  • 0

I’m trying to write a greasemonkey script that only displays photos with the tags bacon.

The site it runs on is written like so:

<div class="photos">
<ul>
...
<li>
<a href="photo1"> <img src="http://somesite.co/photo1.jpg" </a> <br /> <a href="tags_photo1"> <span class="tags">&nbsp;bacon, delicious&nbsp;</span> </a>
</li>
...
</ul>
</div>

At first I tried using DOM by acessing div and then using childNodes. I could access the img and both href nodes, but not span.

Next I tried using this to get the tags from the span:

tagNodes=document.getElementsByClassName('tags');

And it returned a XPCNativeWrapper collection all of whose elements were undefined.

Any ideas as to how to get at the tags?I’m fairly new to javascript, so I’m sorry if my question is stupid.

[Edit]

var spans, tags;    
spans = document.getElementsByTagName('span');
for (var i = spans.length - 1; i >= 0; --i)
{
    tags = spans[i];
    alert(tags.wrappedJSObject.nodeValue);
}

Returns as null, even with wrappedJSObject. Is it because Object.prototype doesn’t work for XPCNativeWrapper? Or am I missing something?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T04:53:16+00:00Added an answer on May 16, 2026 at 4:53 am

    Using pure Javascript (rather than using a library like jQuery – which I don’t think you can use in a greasemonkey script), this should work:

    var spans = document.getElementsByTagName("span");
    for(var i = spans.length - 1; i >= 0; i--) {
        if(spans[i].className == "tags") {
            var span = spans[i];
            // do something to span
        }
    }
    

    You might want to look into using jQuery, if you can, because the code in jQuery would be:

    $("span.tags").each(function() {
        var span = this;
        // do something to span
    });
    

    [EDIT]

    You might be having problems because your img tag isn’t closed.

    Once you get access to the span with the tags in it, you just need to get it’s innerHTML property.

    This code will remove the whole list item, if the tags element doesn’t contain “bacon”:

    var spans = document.getElementsByTagName("span");
    for(var i = spans.length - 1; i >= 0; i--) {
        if(spans[i].className == "tags") {
            var span = spans[i];
            if (!span.innerHTML.match(/bacon/i)) {
                var li = span.parentElement.parentElement;
                li.style.display = "none";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.