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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:15:03+00:00 2026-05-28T13:15:03+00:00

I am making a table display optimization of my website when the windows width

  • 0

I am making a table display optimization of my website when the windows width gets below 500px, in which I want the tables to only have 2 columns; Title, Teaser.

As of now I am chaining like this:

var $rows = $(".zn-listviewtable tr");
if ($rows.children('td').length > 3) {
    $rows.find("td:gt(2)").remove().end().find("th:gt(2)").remove().end().find("td:lt(1)").remove().end().find("th:lt(1)").remove();
}

As you can see I have an if-statement checking if there’s more than 3 columns (or td‘s) and if so, then remove all that is > 2 and < 1.

The only field which is < 1 is a checkbox field in each row. Not all my tables has this field, so I only want to apply the remove() on those which does have it.

Is there a way to check of this during the chaining rather than splitting it up and then start all over in a seperate one, avoiding it ending up like this:

var $rows = $(".zn-listviewtable tr");
if ($rows.children('td').length > 3) {
    $rows.find("td:gt(2)").remove().end().find("th:gt(2)").remove();
}
if ($rows.children('td').find('input:checkbox').length > 0) {
    $rows.find("td:lt(1)").remove().end().find("th:lt(1)").remove();
}
  • 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-28T13:15:04+00:00Added an answer on May 28, 2026 at 1:15 pm

    First, it’s easier to write:

    $rows.find("td:gt(2)").remove().end().find("th:gt(2)").remove().end().find("td:lt(1)").remove().end().find("th:lt(1)").remove();
    

    as:

    $rows.find("td:gt(2),th:gt(2),td:eq(0),th:eq(0)").remove();
    

    If you want to chain everything you’ll need to assign a class to tables that have a first column of checkboxes (or the first tds and th)

    Otherwise, you can:

    if ($rows.find('td:eq(0):has(input[type="checkbox"])').length)
        $rows.find("td:eq(0),th:eq(0)").remove();
    
    $rows.find("td:gt(1),th:gt(1)").remove();
    

    Which conditionally removes the checkbox column, and leaves 2 columns

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

Sidebar

Related Questions

I am making a table in which you can add aditional rows. When you
I want to update a column in a table making a join on other
When making relations between tables (in mysql), I have encountered a naming dilemma. For
Possible Duplicate: Datetime vs Timestamp? I have a Mysql table, which has a column
If I am making a module, and want to have two custom paths: path/path/path/index.htm
I'm making a forum in PHP. I have to display all forum categories in
I want to center an image of unknown width/height on a page, while making
I am making a small iPhone application in which I have implemented the database
I am making a social networking site where I want to have a user's
I have a table with many columns, some of which have divs which are

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.