最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin5浏览0评论

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>
发布评论

评论列表(0)

  1. 暂无评论