1

Would like to hide some text inside a div-block, but I don't want to hide the whole div element, because there are other elements inside, which I need.

Please suggest a solution using jquery.

1
  • Can you please show some sample HTML? Can you put the text in question in a child span or div and then hide that? Commented Dec 19, 2011 at 6:07

5 Answers 5

3

Put the text in a span, and hide that

Depending on the structure it could be something like this

<div id="yourDivId">
   <span>Hi There</span>
</div>

$("#yourDivId span:first").hide();
Sign up to request clarification or add additional context in comments.

Comments

2

You can do this by putting that code in a span. and hiding that span will hide that text only. not the whole div.

HTML:

<div id="whole">
  <span class="text">your text goes here</span>
</div>

JQuery:

$(document).ready(function(){
    $(".text").hide();
});

Hope this helps.

Comments

0

It depends on your html structure, here is my suggestion.

<div class="parent">
  <p class="children">Some text here</p>
</div>

$(".children").hide()

Comments

0

Identify the elements that you want to hide. Wrap them with any div or span with unique id. So, you can hide with jQuery as mentioned above.

Comments

0

Span is the best way to divide the block level elements. Use span for the different section of the text you want to segregate and hide/show the span using jquery.

<div>
 <span class="show"> text1 </span> <span class="hide"> text2 </span> <span class="show"> text3 </span>
</div>

<script>
$(".hide").hide();
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.