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

  • SEARCH
  • Home
  • 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 3308612
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:32:31+00:00 2026-05-17T21:32:31+00:00

I am working on a project, which requires me to select a item from

  • 0

I am working on a project, which requires me to select a item from the categories navigation, which contains a “rel” attribute like (category-action, category-adventure, etc). As you can see from my demo: My Demo Script, it works on the first two categories, however, it does not work with the last two. Why is this? and how can I fix it?

Here is my current script:

$(document).ready(function()
{
    $("#sidebar ul li a").each(function()
    {
        var categories = $(this).attr("rel");
        var entries = $("#content-main .blog-entry").attr("rel").split(" ")

        $(this).hover(function()
        {
            for(i = 0; i < entries.length; i++)
            {
                if(entries[i] == categories)
                {
                    $("#content-main .blog-entry[rel~="+categories+"]").each(function()
                    {
                        $("#content-main .blog-entry[rel~="+categories+"]").addClass("match");
                    });
                }
            }
        },
        function()
        {
                $("#content-main .blog-entry[rel~="+categories+"]").each(function()
                {
                    $("#content-main .blog-entry[rel~="+categories+"]").removeClass("match");
                });
        });
    });
});

and here is my html file, if you don’t want to view the web page… although I’d strongly suggest viewing it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Big Fish Challenge</title>
    <link href="static/css/foo.css" type="text/css" media="all" rel="stylesheet" />
    <link href="static/css/common.css" type="text/css" media="screen" rel="stylesheet" />
</head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js" type="text/javascript"></script>
    <script src="static/js/common.js" type="text/javascript"></script>
<body>
<!-- primary container -->
    <div id="container">
        <!-- site header -->
            <div id="header">
                <h1><a href="index.html">ClassicGamer.com</a></h1>
            </div>
        <!--/site header -->
        <!-- content wrapper -->
            <div class="clearfix" id="content-wrapper">
                <!-- sidebar -->
                    <div class="float_left" id="sidebar">
                        <h3 class="header-categories">Categories</h3>
                        <ul>
                            <li><a href="#" rel="category-action">Action</a></li>
                            <li><a href="#" rel="category-adventure">Adventure</a></li>
                            <li><a href="#" rel="category-card-games">Card Games</a></li> 
                            <li><a href="#" rel="category-rpg">RPG</a></li>                                                       
                        </ul>
                    </div>
                <!--/sidebar -->    
                <!-- content main -->
                    <div class="float_left" id="content-main">
                        <div class="blog-entry" rel="category-action category-adventure">
                            <h1>My Action Game</h1>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id nibh purus. Aliquam interdum commodo libero, quis aliquet massa lobortis vel. Nunc rhoncus ullamcorper nulla, ac molestie lorem blandit a. Pellentesque ut massa tellus[...]</p>
                        </div>
                        <div class="blog-entry" rel="category-action">
                            <h1>My Action Game</h1>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id nibh purus. Aliquam interdum commodo libero, quis aliquet massa lobortis vel. Nunc rhoncus ullamcorper nulla, ac molestie lorem blandit a. Pellentesque ut massa tellus[...]</p>
                        </div>
                        <div class="blog-entry" rel="category-rpg">
                            <h1>My Action Game</h1>
                            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id nibh purus. Aliquam interdum commodo libero, quis aliquet massa lobortis vel. Nunc rhoncus ullamcorper nulla, ac molestie lorem blandit a. Pellentesque ut massa tellus[...]</p>
                        </div>                                                  
                    </div>
                <!--/content main -->
            </div>
        <!--/content wrapper -->
        <!-- footer -->
            <div id="footer">

            </div>
        <!--/footer -->
    </div>
<!--/primary container -->
</body>
</html>

A million thanks to those who reply, thank you for your time.

  • 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-17T21:32:32+00:00Added an answer on May 17, 2026 at 9:32 pm

    You could simplify all your javascript code to

    $('#sidebar li a').hover(
        function(){
            $('div[rel*=' + $(this).attr('rel') +']' ).addClass('match');
            },
        function(){
            $('div[rel*=' + $(this).attr('rel') +']' ).removeClass('match');
        }
    );
    

    and even simpler would be to use this.rel instead of the jquery equivalent $(this).attr('rel') as @lonesomeday commented..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on a project which requires migration of content from different
I'm working on a project for a government agency which requires 508 compliance. Our
Hi I'm working on a project which requires I use a large number of
I'm working on a project which requires me to work with .Net Framework 3.5
I am currently working on this project which requires me to make a function
I'm working on a Project Euler problem which requires factorization of an integer. I
I am working on a login section for a new project, which definitely requires
I'm working on a project which is just about to start, and since I
I'm working in a project which needs to clean up some third party XSD
I am working on a project which uses an import #import progid:Blah.blah.retrieve rename_namespace(Blah) but

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.