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 6246697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:44:19+00:00 2026-05-24T12:44:19+00:00

Since I’ve been experimenting with jQuery for just a few days now, a few

  • 0

Since I’ve been experimenting with jQuery for just a few days now, a few things (like arrays) are still breaking my brain. Unraveling a indexOf function, for example, feels like trying to turn right while backing out a driveway, in England. Regardless, I took a stab at applying a class based on a comparison of one div to the index of another…and (of course) I can’t get it to work. Hopefully, you can tell me if I’m “warm” with the following script. Or, if not, how to fix it.

In short: The basic idea is that if you hover over any .elbox div, the script compares the text in the .skemps div of that elbox to the content in each .pjemp div; and, if it finds a match, applies a class to the matching .pjemp div.

Div1: #ptosEmps li div

<div id="ptosEmps"> 
 <div class="menu">
  <ul id="menu"> 
    <li><div class="pjemp"><a>T</a></div></li>
    <li><div class="pjdesc">T Description</div></li>
    <li><div class="pjemp"><a>I</a></div></li>
    <li><div class="pjdesc">I Description</div></li>
    <!-- ... (one primary li and description li for each of the .skemps letters -->
  </ul>
 </div>
</div>

Div2: #ptosTable .elbox .skemps

<div id="ptosTable">
 <div class="elbox">
  content
  <div class="skemps">T,I,H,P,W,L,N,F</div>
 </div>
 <!-- About 100 of these. .skemps div can contain one or more of those letters. -->
</div>

Script (doesn’t work):

$('#ptosEmps li').filter(":even").hover(function() {
    $(this).filter(function() {
    return $('#ptosTable .skemps').text().indexOf($('.pjemp').text()) == -1;
        //if skemps = any text in menu div, return true?
    }).addClass('.emp_hi');
},
function() {
    $(this).removeClass('.emp_hi');
});

I think maybe I need to somehow define the entire filter function as a $(this), then say something like “$(this).addclass(‘.emp_hi’);” But how?

———-

For the record, I forgot to mention that the text in Div2 (which triggers addClass in Div1) was also hidden via css. So, working from BumbleB2na’s suggestion, this is what I ended up with (WORKS!):

$('.elbox').hover(function() {
    var arrSkemp = $(this).children('.skemps').text().split(',');
    $.each(arrSkemp, function(index, value) {
        $('.pjemp:contains(' + value + ')').addClass('emp_hi');
    });
},
function() {

    $('.pjemp').removeClass('emp_hi');
});

Props to BumbleB2na—both for helping me to work out the kinks in my question and for a speedy, very functional response that did not break my brain!

  • 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-24T12:44:21+00:00Added an answer on May 24, 2026 at 12:44 pm

    K try my jsfiddle out and maybe it will help. I couldn’t get indexOf() to work but here’s the code I would go with:

    $('.skemps').hover(function() {
        var arrSkemp = $(this).text().split(',');
        $.each(arrSkemp, function(index, value) { 
            $('.pjemp:contains(' + value + ')').addClass('emp_hi');
        });
    },
    function() {
        var arrSkemp = $(this).text().split(',');
            $.each(arrSkemp, function(index, value) { 
                $('.pjemp:contains(' + value + ')').removeClass('emp_hi');
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since Rails is not multithreaded (yet), it seems like a threaded web framework would
Since I started this new webshop for a friend to launch, which still in
Since I've known about Node.js, I've always been a fan of it. But today
Since I am not getting anywhere with my previous question , I would like
Since visual studio added support for JQuery, I am wondering how to create a
Since I started learning Objective-C and Cocoa, I've been wondering why they have chosen
Since the C# using statement is just a syntactic sugar for try/finally{dispose}, why does
Since I run my stuff in a VM I like to save my data
Since many modern browsers support CSS3, I would like to use many CSS 3
since last week I've been busy with mvc3. I'm new to the whole .net

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.