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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:51:28+00:00 2026-06-06T03:51:28+00:00

Question: I am trying to fire a .click() event if a <ul></ul> element has

  • 0

Question:

I am trying to fire a .click() event if a <ul></ul> element has no DOM within it.

The thought process behind this code is, when the user clicks the x the item slides left, and then is .remove() from the DOM. As a result of my beautifully whitespaced HTML, its leaving line breaks and spacing within the ul still. As such i can’t get the if() statement to function properly.

Even by using $.trim() and then comparing it still won’t fire the .click() event.

Picture Of The HTML

enter image description here

HTML

    <div class="btn-group pull-right nav-notice">
      <span class="badge badge-info nav-notice-button">8</span>
      <div class="notice-container">
        <span class="notice-arrow"></span>
        <ul class="notice-container-list">
          <li><span class="label label-warning">Warning</span><span class="notice-message">Warning 12315125</span><i class="notice-remove icon-remove-circle"></i></li>
          <li><span class="label label-success">success</span><span class="notice-message">Warning 12315125</span><i class="notice-remove icon-remove-circle"></i></li>
          <li><span class="label label-important">important</span><span class="notice-message">Warning 12315125</span><i class="notice-remove icon-remove-circle"></i></li>
        </ul>
      </div>
    </div>

jQuery

//live(), looking for past/present DOM
$('.notice-remove').live( "click", function(){
    //no double dipping!
    $this = $(this);
    //Hide the x item, improves the animation a bit
    $this.hide();
    //animate the width of the li, to give it a slideoff effect
    //when the animate completes, remove the element from the DOM
    $this.parent('li').animate({
        width: "0"
    }, 'fast', '',
    function(){
        $(this).remove();
    });
    //get the html contents of the ul element
    var str = $('.notice-container-list').html();
    //trim the contents of the ul, and if they are exactly empty
    //fire the click event to close the container
    if( $.trim(str) === "" ){
        log('Closing the Notice');
        $('.nav-notice-button').click();
    }
});
  • 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-06T03:51:29+00:00Added an answer on June 6, 2026 at 3:51 am

    I doubt it will work this way. See, you’re checking the element right after you declare some animate functionality for it. But that function will not be called immediately – that’s the whole point of animate()! And this, it turn, means that when you check <ul> contents, it’s still not empty.

    Use the following technique instead: check how many elements are left in <ul> when removing <li>; if there’s none of them, remove the <ul> itself:

    $this.parent('li').animate({
            width: "0"
        }, 'fast', '',
        function(){
            var $li = $(this);
            if (! $li.siblings().length) {
               $li.parent().remove();
            }
            else {
               $li.remove();
            }
        });
    

    Here’s a working jsFiddle (had to put something texty in <i></i>, cannot use your css’ icons). For the same reasons I used simple .parent().remove() instead of triggering the $('.nav-notice-button').click(), as I don’t know what should be done with that click. )

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

Sidebar

Related Questions

I am having trouble trying to get a click event to fire after the
Question: I'm trying out to convert this here: http://support.microsoft.com/kb/828736 to VB.net I got it
hello i have this question i was trying to find a way to call
This is a question based on: Trying to get tag-it to work with an
Following on from this question...I'm trying to unit test the following scenario: I have
This seems to be the same as my question: jquery ui tabs load event
This might be a very dumb question but, is there a way to fire
I know this question has probably been answered over 200 times and I have
I'm using the code from this question to autoplay an iframe embedded Youtube video
This question is relating to a specific functionality that a client has requested for

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.