2

In the following div:-

<div>
     My Text that needs to be hidden 
    <span style="font-size: 21px">Other text Other things</span>
</div>

I just want to hide the text My Text that needs to be hidden. Is it possible?

Steve
  • 2,546
  • 8
  • 49
  • 94
  • 5
    possible duplicate of [Hide text node in element, but not children](http://stackoverflow.com/questions/15196630/hide-text-node-in-element-but-not-children) – ctwheels Aug 25 '14 at 18:29
  • 1
    Basically the question doesn't have an obvious search text for it. May be that's how I missed it. – Steve Aug 25 '14 at 19:41

2 Answers2

3

Html:

<div>
    <span id="mySpan" >My Text that needs to be hidden</span> // Add a span with a id
    <span style="font-size: 21px">Other text Other things</span>
</div>

JQuery:

$(document).ready(function(){
    $('#mySpan').css('display', 'none');
});
Clément Bisaillon
  • 5,037
  • 8
  • 32
  • 53
2
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide("slow",function(){
      alert("The paragraph is now hidden");
    });
  });
});
</script>
</head>
<body>

<button>Hide</button>
<div>
     <p>My Text that needs to be hidden </p>
    <span style="font-size: 21px">Other text Other things</span>
</div>
</body>
</html>
user3250183
  • 506
  • 6
  • 19