jQuery has and contain
The :has() filter finds elements that contain another selector. For example, say you want to find all rows in a table that has a link then you can use$("tr:has(a)")
The following example highlights all the rows of a table that contains a link
<html> <head> <script type="text/javascript" src="jquery-1.8.0.min.js"></script> <script> $(document).ready(function(){ $("tr:has(a)").css("background-color", "pink"); }); </script> <body> <h1>List of Cars </h1> <table border=1> <tbody> <tr> <td>S No.</td> <td>company</td> </tr> <tr> <td>1</td> <td>Reference Designer</td> </tr> <tr> <td>2 </td> <td><a href ="http://google.com"> google </a></td> </tr> <tr> <td>3 </td> <td>Yahoo</td> </tr> </tbody> </table> |
You may like to try this example here.
:contains() is another filter that finds elements that contain specific text. For example, to find every link that says "here" you can create a jQuery object like this:
$('a:contains(here)')
As an exercise you may want to modify the example so that it makes use of
contains
.