1

Possible Duplicate:
jQuery: Find the text of a list item that contains a nested ul

<div id="pro">
<ol></ol>
<li id="4331">Region
      <ul>
         <li id="4332">Asia</li>
         <li id="6621">Europe</li>
      </ul>
</li>
</div>

If I Click on Region only display Asia & Europe and Hide the Region when is clicked

i am using the .hide() method here is what i did so far:

$(document).ready(function() {
    $("li").live("click", function(event) {
        $("li").hide(); 
        event.cancelBubble = true;
        loadChild($(this).attr("id"), event);
        return false;
    })
});

my current output is:

<div id="pro">
<li id="4331" style="display: none;">
Region
   <ul>
      <li id="4332">Asia</li>
      <li id="6621">Europe</li>
   </ul>
</li>
</div>

It hides everything...

but I want to hide only the parent Region
I want to be able to click on it and after clicking hide Region and show Asia And Europe only.

if possible to display both at different div like

click on Region its display in div 1 and there child on div 2

then also give the answer how it possible..

Please help me out with this thanks.

4

3 回答 3

2

您不能在display: none不影响所有子项的情况下将元素设置为(或其同类)。就是那样子。通过将父级和子级设置font-size为某个可见值,仍然可以在显示子级内容的同时伪隐藏“父级”内容:0font-size

http://jsfiddle.net/ExplosionPIlls/MPCEa/

event.cancelBubble = true;可以替换为e.stopPropagation()

$("li").hide();在方法的范围内应该是$(this).hide()。否则会影响到文档中的所有 <li>s。

.live死了。将您的代码至少更新到 jQuery 1.7 并使用.on.

于 2013-02-01T05:32:38.650 回答
0

你不能真正隐藏它,但你可以通过抓住文本节点并删除它来删除它。

$("li#4331").contents().filter(function() {
  return this.nodeType == 3;
}).remove();

http://jsfiddle.net/TLpk9/6/

于 2013-02-01T05:51:34.967 回答
0

<span>如果你可以用标签包裹“区域” ,你可以有更好的控制。

于 2013-02-01T06:05:55.793 回答