简体   繁体   English

Jquery获得li href的父级

[英]Jquery get parent of li href

Hi I want to get the parent of this li 嗨,我想得到这个李的父母

     <li><a href="/panasonic/index.php/en/site/wheretobuy" class="WTB"></a>
        <ul>        
    <li><a href="/panasonic/index.php/en/showroom/index" id="myid" > testing</a> </li>    
       </ul>    
   </li>

How can I get the parent href of "myid". 如何获得“myid”的父href。

All I have is this 我只有这个

document.write($('#myid').parent('li').find('a').attr('href'));

Which displays ".../showroom/index", I use document.write() just to test. 其中显示“... / showroom / index”,我使用document.write()来测试。

I want it to display ".../wheretobuy" and it has to be accessed via "myid" 我希望它显示“... / wheretobuy”,它必须通过“myid”访问

here it is here 在这里

http://fiddle.jshell.net/86powers/YLYxF/ http://fiddle.jshell.net/86powers/YLYxF/

Thanks 谢谢

$('#myid').closest('ul').parent().find('a').attr('href')

这应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM