Select all 'tr' except the first one
By adding a class to either the first tr
or the subsequent tr
s. There is no crossbrowser way of selecting the rows you want with CSS alone.
However, if you don't care about Internet Explorer 6, 7 or 8:
tr:not(:first-child) {
color: red;
}
Select all except first and last td element in one selector
It is syntactically correct, as you can quickly check using the W3C CSS Validator. The validator is known to have errors, so in principle, you should check the rule against CSS specifications, especially Selectors Level 3. The result is still that yes, it is correct.
It also has the desired meaning, since this is how selectors combine. You can use :not(...)
selectors to express a condition of type “not ... and not ...”.
This applies provided that all children of tr
elements are td
. If there are header cells, i.e. th
elements as well, then the selector applies to those data cells (td
elements) that are not the first data cell or the last data cell in a row with .red
class.
Jquery- Hiding all tr except the first one
You can exclude the first element using .not()
method:
$('table tbody tr').not(':first').hide();
And for selecting the next hidden tr
element you can use .nextAll()
and :hidden
selector:
var $row = $this.closest("tr").nextAll(':hidden').first();
Select all tr except last and first ones with .on()
:first and :last match the first and last element in the jQuery object. Since you're using on()
, that selector will be evaluated in the context of a jQuery object containing a single element (the event target). Therefore, that element will never be matched, as it is both the first and last item in the set.
Contrast :first-child and :last-child, which match the first and last element in the parent element. Using them should solve your problem:
$("#id").on("click", "td:not(:first-child, :last-child)", callback);
jquery - get all rows except the first and last
Drop the gt()
, as I'd assume it's a tiny bit slower than :first
.
Use not()
in conjunction with :first
and :last
:
$('table#tbl > tbody > tr').not(':first').not(':last').addClass('highlight');
Most browsers automatically add an tbody
element in the table markup if that's missing, that is why the immediate children selector was failing – there were no <tr>
elements as an immediate children to the <table>
tag.
I am not 100% sure this is the way all browsers do it, so it would be safer to just add the <tbody>
manually. Otherwise you need a little sniffing and cannot do it as an one liner:
if($('table#tbl > tbody').size() > 0) {
$('table#tbl > tbody > tr').not(':first').not(':last').addClass('highlight');
} else {
$('table#tbl > tr').not(':first').not(':last').addClass('highlight');
}
Hope this solves your problem!
jQuery How to get the all rows HTML except first?
Because html
method returns the html
contents of the first matched element.
Get the HTML contents of the first element in the set of matched elements.
You can use the each()
method, try this:
$('#files-table> tbody > tr').not(':first').each(function(){
console.log($(this).html())
})
Fiddle
You can define a variable and store the html contents of the matched elements:
var html = '';
$('#files-table> tbody > tr:not(":first")').each(function(){
html += $(this).html()
})
Select all children except first one of element
Use :not(:first-child)
to exclude the first link
.myClass img { content: url('http://kenwheeler.github.io/slick/img/lazyfonz2.png');}
.myClass a:not(:first-child) img { content: url('http://kenwheeler.github.io/slick/img/lazyfonz3.png');}
<span> <span class="myClass"> <a> <img> </a><a> <img> </a><a> <img> </a></span> </span>
How to select not first tr and not last td
Use the :not(), :first-child and :last-child.
#myTable tr:not(:first-child):hover td:not(:last-child) {
background: #dfdfdf;
}
Also see this example.
Related Topics
How to Detect If the Os Is in Dark Mode in Browsers
How to Make Twitter Bootstrap Modal Full Screen
Faster Way to Develop and Test Print Stylesheets (Avoid Print Preview Every Time)
Make Font Awesome Icons in a Circle
Which Are the Most Important Media Queries to Use in Creating Mobile Responsive Design
Symfony2 - Assetic - Load Images in CSS
How to Remove the Gloss on a Select Element in Safari on MAC
Display Image at 50% of Its "Native" Size
Css: Background Image on Background Color
Make Column Fixed Position in Bootstrap
Background-Size in Shorthand Background Property (Css3)
Why Use an Attribute Selector to Match Classes
CSS for Star Ratings via Fontawesome
Without Media Queries How to Achieve 3 Column Desktop to 1 Column Mobile Layout