2013年12月16日 星期一

[程式] jQuery Tips

  • (Selector) 選取Nested Item
    ex.
    欲選取下方程式碼中 class 為 next_page 的 href
    <div class="load_more">
        <div class="pagination">
            <em class="current">1</em>
            <a class="next_page" rel="next" href="/category_posts/books?page=2">2</a>
        </div>
    </div>
    => $(".load_more .pagination .next_page").attr("href")
  • (Selector) 利用 ".text()" 選取 <...>和</...> 間的文字
    ex.
    欲選取<a id="myID">This is a link</a>中的"This is a link"
    => $.("#myID").text()

沒有留言:

張貼留言