-1

This, I thought, was a very simple query, but I seem to be getting lost in the find/hide code.

To simplify:

I may have something like this <h1 class="begin-page"> TEST AREA</h1>

I want to find the text "TEST AREA" and hide it.

How can I accomplish that via jquery?

Thank you.

4

4 回答 4

3
$('h1:contains("TEST AREA")').html('');

jsFiddle example

于 2013-05-01T18:40:37.590 回答
1
$(function() {
    $('h1.begin-page').html($('h1.begin-page').html().replace("TEST AREA", ""));
});
于 2013-05-01T18:36:29.577 回答
0

复制代码-

<script>
$(document).ready(function(){
  $("#hb").click(function(){
    $("h1.begin-page").hide();
  });
});
</script>
    <p id="hb">hide</p>
    <h1 class="begin-page"> TEST AREA</h1>

或者,如果您愿意,可以仅在函数中隐藏和显示-

<script>
$(document).ready(function(){
  $("#hb").click(function(){
    $("h1.begin-page").toggle();
  });
});
</script>
    <p id="hb">[hide/show]</p>
    <h1 class="begin-page"> TEST AREA</h1>

没有额外的代码 -

      $(function(){
        $("h1.begin-page") // find the text
.hide(); // hide it
      });

来自 - http://www.w3schools.com/jquery/jquery_hide_show.asp

于 2013-11-09T16:23:20.907 回答
0
$(function() {
    $('h1.begin-page')  // target the h1 element with class 'begin-page'
      .hide();          // hide it
});
于 2013-05-01T18:34:44.983 回答