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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T07:23:14+00:00 2026-06-03T07:23:14+00:00

i have a function to find the length of finding class, but it not

  • 0

i have a function to find the length of finding class, but it not working always return the length is ‘0’;

some thing is wrong with my code: can any one advice me the proper way. but i need to use the same structure of the code style to achieve this.

look on to my code :

<div id='list'>
  <ul>
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>      
  </ul>
    <p></p>
</div>​

function callMe(params){
    $(params.list).click(function(){
       $(this).addClass('c_on');
        var length = $(params.list).find('.c_on').length;
        $('p').text(length)// return always 0, even i clicked no.of list.        
    })
}

$(document).ready(function(){
    var obj = {
        list : $('ul').find('li')      
    }
   callMe(obj);
})

style :

li.c_on{
border:1px solid green;
}

​
​Here is the fiddle : http://jsfiddle.net/AeGvf/1/

  • 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-03T07:23:16+00:00Added an answer on June 3, 2026 at 7:23 am

    You’re using find:

    Get the descendants of each element in the current set of matched elements, filtered by a selector, jQuery object, or element.

    when you should be using filter:

    Reduce the set of matched elements to those that match the selector or pass the function’s test.

    Note that find works on the descendants whereas filter works on the elements themselves. You have a list of <li>s that don’t have any descendants so find is searching an empty set. You should do this:

    var length = $(params.list).filter('.c_on').length;
    

    Also, your params.list is already a jQuery object so you don’t need to $(params.list), you can use params.list directly:

    function callMe(params){
        params.list.click(function(){
            $(this).addClass('c_on');
            var length = params.list.filter('.c_on').length;
            $('p').text(length);
        });
    }
    

    Demo: http://jsfiddle.net/ambiguous/uCGaY/

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

Sidebar

Related Questions

I have been messing around with Leaks trying to find which function is not
Maybe is a dumb question, but I can't find the proper function: I have
I have been unable to find any decent documentation on this function. The code
I have the most basic jquery function of them all, but I couldn't find
I have this part of the function : $jQ('.product-collateral .product-tabs li').each(function(index){ $jQ(this).attr('id', $jQ(this).find('h3').attr('class')); if(index
I have a Find function in order to find an element from a BST
so I find myself in the awkward situation where I have a function in
I need the regex to find function calls in strings in php, I have
I have a quick question here. I know that the cakePHP find('first') function returns
I'm trying to find out where this function comes from. Any one have any

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.