2013-04-05 76 views
1

By Sharepoint通过一些元素在内部生成一堆tds。所以只是为了清楚我不能编辑或更改元素,因为它生成。如何隐藏.each()以外的特定元素Jquery

我想做到的是给所有throught和'.js-contentFollowing-itemLink'然后遍历如果的.text()包含了我要找的'<span> Stop following</span>'应该成为隐藏与'.hide()'的具体文本。

我似乎无法完成这个我已经尝试了很多方法。

这里是的jsfiddle: http://jsfiddle.net/QXwyk/3/

还拿我不能抢ID,它是独一无二的,许多这些元素具有不同的价值观和文本生成通知。

HTML:

<span class="ms-contentFollowing-itemTitle"> 
<a href="#" class="js-contentFollowing-itemLink">test</a> 
</span> 

<br> 
<div class="js-contentFollowing-itemUrlDiv"> 
<span class="ms-metadata ms-contentFollowing-itemUrl"></span> 

    <input type="text" readonly="readonly" class="ms-metadata ms-contentFollowing-itemUrl ms-contentFollowing-itemFullUrl" style="visibility: visible; border-color: transparent; background-color: transparent;"> 
</div> 
<a href="#" class="ms-secondaryCommandLink"><span>Stop following</span></a> 

我的JS:

$('.js-contentFollowing-itemLink').each(function() { 
     if ($(this).text() == "test") 

      $(this).closest("span").hide(); 


    }); 

注:我知道它会隐藏错误的元素,但如果语句的工作的声明,如果我不能做到我里面的代码需要隐藏'停止追踪'。这个JS只是我所做的那个不起作用的例子之一。

$('.ms-secondaryCommandLink span').hide();试图if语句内但删除了所有与<span>“别跟着”:/

感谢一大堆!

回答

0

的Html

<div class="ms-content"> 
<span class="ms-contentFollowing-itemTitle"> 
<a href="#" class="js-contentFollowing-itemLink">test</a> 
</span> 

<br> 
<div class="js-contentFollowing-itemUrlDiv" id="contentFollowingUrl_18" url="http://dev/socialsites/Utförsåkning"> 
<span class="ms-metadata ms-contentFollowing-itemUrl"></span> 

    <input type="text" readonly="readonly" class="ms-metadata ms-contentFollowing-itemUrl ms-contentFollowing-itemFullUrl" style="visibility: visible; border-color: transparent; background-color: transparent;"> 
</div> 
<a href="#" class="ms-secondaryCommandLink"><span>Stop following</span></a> 
</div> 

JS

$('.js-contentFollowing-itemLink').each(function() { 
    if ($(this).text() == "test") 
     var text = $(this).closest('.ms-content').find('.ms-secondaryCommandLink').hide(); 
}); 

http://jsfiddle.net/QXwyk/4/

+0

aaah做了一些更改,它是我正在寻找的.find()方法。谢谢! – Obsivus 2013-04-05 09:55:10

1

代码中的几个问题:

$('.js-contentFollowing-itemLink').each(function() { 
    if ($(this).text() == "test") 
    var text = $(this).parent().parent().parent().hide); <-- hide not closed properly 
} <--- Extra bracket here.. 
}); 

工作代码:

$('.js-contentFollowing-itemLink').each(function() { 
    if ($(this).text() == "test") { 
     var text = $(this).parent().parent().parent().hide(); 
    } 
}); 
+0

哦,是的,我错了它看起来不像在我的VS抱歉,我对 – Obsivus 2013-04-05 09:45:49

0

您可以选择遵循的方式包含特定文本的对象,在此基础上,你可以可以做其余的动作......

示例:$(” JS-contentFollowing-itemLink:包含(测试)')。隐藏();将隐藏“测试”