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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:22:58+00:00 2026-06-05T06:22:58+00:00

I am in a predicament. I have been trying to compare two variables in

  • 0

I am in a predicament. I have been trying to compare two variables in javascript and then assign a class to parent element if matched. But i am having no success in this. I have searched through all possible codes and tried them but not able to get it working. The code i have written so far is as below:

$('div#encased a').click(function(){
        $('ul#filter .current').removeClass('current');
        var class_name = ($(this).parent().attr('class').replace('-',' '));
        var className = class_name.toString();
        alert(className);
        $('ul#filter li').each(function(){
            /*1st version
            var filterValue = $(this).text().toLowerCase();
            var filterValstr = filterValue.toString();
            alert(filterValstr);
            if(filterValstr==className)
            {
                alert("match!")
                $(this).parent().addClass('current');   
            }*/

            /*2nd version*/
            if($(this).text().toLowerCase() == class_name)
            {
                $(this).parent().addClass('current');   
            }
            /*this works which according to me means it is not entering the if clause
            else{
                $(this).parent().fadeOut('slow').addClass('hidden');    
            }*/
        });
    });

As per my knowledge the value is not going inside the if command at all as i tried using else function and that works. I am sure theres some silly error i am doing. I have tried 2 methods here and i have commented one but presented both of them here to know if any of them should be correct.

Basically on click of an image in my div#encased element the class name of the image is taken and then compared with the text in the filter menu above. If it matches the matched filter text should be assigned the class of current. Hope you are getting what i am trying to explain. Please help. thanks

  • 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-06-05T06:23:00+00:00Added an answer on June 5, 2026 at 6:23 am

    Your code isn’t clear, and kind of a spaghetti one, but maybe your problem is with white spaces, try trim them

    var filterValue = $.trim($(this).text().toLowerCase());
    

    And you should know that string.toString() return the string…
    Example:

    var str = "bla bla bla";
    alert(str.toString === str); // true!
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ok I'm kinda in a predicament right now. I have a java program that
Ok, the title is a bit confusing, but here's my predicament. I've made a
I'm having a little predicament switching between views, here. Alright, so, I have this
I have looked everywhere for the answer to this question, but cannot find anything
I just started C++ but have some prior knowledge to other languages (vb awhile
I currently have quite the predicament. An if statement I have written - which
I am in a predicament here. My PHP code used to work but since
I have been searching for an answer to this question for days and it
I have a strange predicament where I can't add onclick to anchor tags. I
I have a bit of an interesting predicament. I have an :ingredients field which

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.