first()方法返回所選元素的第一個元素。
要返回最后一個元素,請使用last()方法。
$(selector).first()
突出顯示第一段:
$(document).ready(function(){ $("p").first().css("background", "coral"); });測試看看?/?
突出顯示第一個DIV元素內(nèi)的第一段:
$(document).ready(function(){ $("div p").first().css("background", "coral"); });測試看看?/?
突出顯示第一個無序列表:
$(document).ready(function(){ $("ul").first().css("background", "coral"); });測試看看?/?