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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:36:53+00:00 2026-05-30T02:36:53+00:00

I’m trying to hide a li list item when the link inside is clicked

  • 0

I’m trying to hide a li list item when the link inside is clicked i.s

<ul>
<li id="list_1" class="list"><a href="http://">hide</a>
</li>

<li id="list_2" class="list"><a href="http://">hide</a></li>

<li id="list_3" class="list"><a href="http://">hide</a></li>

<li id="list_4" class="list"><a href="http://">hide</a></li>
</ul>

<span class="updateNumber">0</span>​

and everytime a li item is hidden, increase the number of updateNumber text by 1. 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-05-30T02:36:54+00:00Added an answer on May 30, 2026 at 2:36 am

    This should do the trick:

    $('li a').on('click', function(e) {
        e.preventDefault();
    
        $(this).parent().hide();
    });
    

    The selector li a finds all <a> tags inside any <li> (I’ve kept it simple here so it’ll be greedy). We then use $.on() to bind an event handler to the click event.

    Now we use an anonymous function (a function without a name) to do our stuff in. Here, we pass e into the function as an argument. e contains the event object so we can do e.preventDefault() on the next line. This line stops the browser doing it’s default behaviour on the link, which is to navigate to the URL in the href attribute in the <a> tag.

    The line $(this).parent().hide() is the important one. Here, $(this) references the link that was clicked, so doing $(this).parent() we can access the parent node (tag) of the <a> which is an <li> in this case. Adding .hide() to the end of it hides the <li> and you’re done.


    To update your .updateNumber span, add this code to your click handler function:

    var currentNumber = parseInt($('.updateNumber').text());
    
    currentNumber++;
    
    $('.updateNumber').text(currentNumber);
    

    The first line gets an integer from the text within your span and assigns it to a variable called currentNumber. parseInt() will attempt to turn whatever is inside the span into an integer.

    The second line currentNumber++; takes the current value we got from the span and increments it by one (the ++) bit.

    We then want to replace the text displayed in the span with the new, updated value, so we put the new value back into the span by using $.text() again:

    $('.updateNumber').text(currentNumber);
    

    Note that using $.text() without passing it a string to use will retrieve the element’s text, whereas supplying $.text() with an argument such as "Hello world, I'm a string" will put that string into the target element.


    Here is a working demo proudly produced and sponsored by @Reigel from the comments.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

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.