开发者

How to get element based on page url

开发者 https://www.devze.com 2023-03-03 14:58 出处:网络
I have navigation in form of ul and li. If url is http://mydomain.com/somewiredpath/page21.htm?p=1 how can i get li element with this url? I don\'t care about rest of the url, need just li with \"page

I have navigation in form of ul and li. If url is http://mydomain.com/somewiredpath/page21.htm?p=1 how can i get li element with this url? I don't care about rest of the url, need just li with "page21.htm".

<ul id="navig">
        <li>
            <a href=".../page1.htm"><imgsrc="..."></a>
        </li>
        <li>
            <a href=".../page2.htm"><imgsrc="..."></a>
            <ul>
                <li><a href=".../page3.htm"><imgsrc="..."></a></li>
                <li><a href=".../page4.htm"><imgsrc="..."></a></li>
            </ul>
        </li>
</ul>

PS: i'm going to add some styles to matched and parent elements, so if there is already some jquery function/plugin for that, it would be great to know.开发者_JS百科


function findLi(pagename) {
    return $('#navig a[href*="' + pagename + '"]').closest("li");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消