javascript - How to hide inline text in div-block using Jquery - Stack Overflow

Would like to hide some text inside a div-block, but I don't want to hide the whole div element, b

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.

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.

Share Improve this question edited Oct 16, 2012 at 16:32 Brian Webster 30.9k51 gold badges157 silver badges227 bronze badges asked Dec 19, 2011 at 6:03 Shibin V.MShibin V.M 4315 gold badges9 silver badges17 bronze badges 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? – nnnnnn Commented Dec 19, 2011 at 6:07
Add a ment  | 

5 Answers 5

Reset to default 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();

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.

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

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

$(".children").hide()

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.

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744378663a4571313.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信