jQuery Page Widget How to - Hide a tag which contains "text"








Question

We would like to know how to hide a tag which contains "text".

Answer


<!--from  ww  w. j a  v a 2s.  c  o  m-->
<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.7.1.js'></script>
</head>
<body>
  <div>some stuff</div>
  <a href="">Question</a>
  <a href="" title="foo">Answer</a>
  <div>some more stuff</div>
    <script type="text/javascript">
    jQuery.noConflict();
    jQuery(document).ready(function(){
       jQuery("a:contains('Question')").hide();
    });
    </script>

</body>
</html>

The code above is rendered as follows: