2013-04-05 35 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:包含(測試)')。隱藏();將隱藏「測試」