Javascript examples for jQuery Selector:parent
The :parent selector selects elements that are the parent of another element including text nodes.
The following code shows how to select all <td> elements with children, including text:
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("td:parent").css("background-color", "red"); });/*from w w w . j av a 2s . co m*/ </script> </head> <body> <h1>Welcome to My Web Page <span>span</span></h1> <table border="1"> <tr> <th>Company</th> <th></th> <th>Country</th> </tr> <tr> <td>A</td> <td>B</td> <td></td> </tr> <tr> <td>C</td> <td></td> <td>D</td> </tr> <tr> <td>E</td> <td>F</td> <td>G</td> </tr> <tr> <td>E</td> <td></td> <td>A</td> </tr> <tr> <td></td> <td></td> <td>U</td> </tr> <tr> <td>K</td> <td>P</td> <td></td> </tr> <tr> <td>L</td> <td>Y</td> <td>C</td> </tr> </table> </body> </html>