jQuery Tutorial Tutorials - jQuery ancestor descendant selector

ancestor descendant selector

The ancestor descendant selector selects every element which are descendants of a element specific by ancestor

jQuery ancestor descendant selector Syntax

$('ancestor descendant')

jQuery ancestor descendant selector Examples

In following example,It would select all list items that are descendant of <ul id="navList"> and place a border around them.A descendant could be a child,grandchild and so on.

example:Select elements using jQuery descendant selector

<style>li{margin:10px}</style>
<ul id="navList">
    <li>
        <ol>
            <li>order list item</li>
            <li>order list item</li>
            <li>order list item</li>
        </ol>
    </li>
    <li>un-order list item</li>
    <li>un-order list item</li>
</ul>
<script>
    $('#navList li').css('border','2px solid coral');
</script>

Try now

Date:2019-08-19 02:23:39 From:www.Lautturi.com author:Lautturi