coder
coder

Reputation: 299

jQuery: Select all children of the last th

I need to select all children of the last th table element.

I already tried something like this:

th:last-children

Thank you very much in advance.

Upvotes: 0

Views: 65

Answers (3)

Samyappa
Samyappa

Reputation: 531

Try this one,

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
    jQuery(document).ready(function(){

        jQuery( "table th:last-child" ).last().css( "color", "red" );
        alert(jQuery( "table th:last-child" ).last().html());
        jQuery("th:last-child").css('background','yellow');

    })
    </script>

Upvotes: 0

Magus
Magus

Reputation: 15104

This line should works :

$('th:last').children();

Upvotes: 1

Milind Anantwar
Milind Anantwar

Reputation: 82231

th:last-children will select th which are last child in their container. you need to use th:last to target last th element along with .children() to get its immediate child elements:

$('th:last').children();

or

$('th:last > *');

Upvotes: 0

Related Questions