DIV CSS 佈局教程網

jQuery parentsUntil() 祖先範圍選取
編輯:JQuery特效代碼     

方法定位

parentsUntil() 會取得目前元素的所有祖先元素,直到遇到符合條件的祖先為止,但符合條件的元素本身不包含在結果中。

語法形式

可使用 $(selector).parentsUntil(expr, filter),也可使用 DOM 元素或 jQuery 物件作為終止條件,例如 $(selector).parentsUntil(element, filter)。

範例說明

例如 $("li").parentsUntil(".inner").css("border", "1px solid blue");,會替 li 到 inner 祖先之間的祖先元素加上藍色邊框。若加上 filter,例如 parentsUntil(".inner", ".second"),只會保留符合條件的祖先。

使用提醒

parentsUntil() 適合限定祖先範圍,避免直接操作到過高層級的容器。使用時要確認終止條件是否正確,否則可能選到非預期的祖先。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved