Hide second row of table jQuery

Go To StackoverFlow.com

2

The first row is the container for search results to be displayed after user types in a keyword and hit search. The second row displays 5 random news results automatically the first time the website loads with no user queries. after the site loads, user types in some keyword and hit search. Now both the results returned as per user keyword and the 5 news pieces will be there. Based on whether the url has any querystring appended to it, if yes, I need to hide the second row. How do i select the second row?

Let's say if the url is just: http://mysite/news/pages/default.aspx then don't do anything if the url is sth like http://mysite/news/Pages/default.aspx?k=city, then hide the second row...

 <div class="NewsResultsList">   
        <table border="1" id="table">
            <tr><td>News Results based on user queries</td></tr>
            <tr><td>Random news results</td></tr>
         </table>
    </div>
2012-04-04 16:51
by Anjana Sharma
Not sure if you're suggesting that the script should sniff the URL. Don't do that. Instead, handle the emptying of the table in the success function of your callback, or do it server side if that's where things are rendered - Michael Haren 2012-04-04 16:56


2

Take a look to this selector

$(document).ready(function (){
    $('div.NewsResultsList table tr:eq(1)').remove()
})​

here's the live example

Note : you should change the id of the row to other name because with that id you could create confusion in your code

2012-04-04 17:00
by Jorge


3

Another option is $(".NewsResultsList table tr :nth-child(2)").hide();.

2012-04-04 17:09
by Whymarrh


2

//This will hide the second row of the table.
$(".NewsResultsList table tr").eq(1).hide();

For reference: http://api.jquery.com/eq/

2012-04-04 16:53
by Kevin Bowersox
For reference: http://api.jquery.com/eq - Michael Haren 2012-04-04 16:55


1

Many solutions. This is one I can think of:

$("#table").first().next().hide();
2012-04-04 16:54
by Enrique Moreno Tent
Ads