我想選擇沒有id
的所有HTML <span>
元素等於x
並將它們隱藏起來。這可能嗎?我認爲你必須使用:not
選擇,但我不能工作了:jquery選擇器 - 選擇id不等於的所有span標籤
$('span:not(#x').attr('style', "display: none;");
任何想法?謝謝 :)。
我想選擇沒有id
的所有HTML <span>
元素等於x
並將它們隱藏起來。這可能嗎?我認爲你必須使用:not
選擇,但我不能工作了:jquery選擇器 - 選擇id不等於的所有span標籤
$('span:not(#x').attr('style', "display: none;");
任何想法?謝謝 :)。
感謝您節省我的一天...... :) –
試試這個
$('span[id!="x"]').attr('style', "display: none;");
至少有三種方法可以滿足您的需求。
$('span:not(#x)').attr('style', "display: none;");
$('span[id!="x"]').attr('style', "display: none;");
$('span').filter(':not(#x)').attr('style', "display: none;");
最有效的方法是$('span[id!="x"]').attr('style', "display: none;");
[jquery docs](http://api.jquery.com/not-selector/)現在說:'。與將推薦的選擇器或變量推入:not()選擇器過濾器相比,not()方法最終會爲您提供更多可讀的選擇。在大多數情況下,這是一個更好的選擇 –
$( 「跨度」)否( 「#X」)隱藏()。 – AutoSponge
看起來你忘了a)。這是否工作? $('span:not(#x)')。attr('style',「display:none;」); – Filip
作爲一個快速的附註,如果你只想隱藏元素,使用'$('span:not(#x)')。hide()',將style屬性設置爲'display:none;'將替換所有現有的內聯樣式,而'hide()'只會添加'display:none;' - 並顯示,只需調用'.show()',只刪除'display:none;'樣式。 – drovani