2013-02-16 73 views
1

喜的父母得到我想要得到這個李jQuery的李HREF

 <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> 

我怎樣才能獲得的「身份識別碼」父HREF的父。

我只有這個

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

該款顯示器 「... /陳列室/指數」,我使用document.write()的只是爲了測試。

我希望它顯示 「.../wheretobuy」,它必須通過 「身份識別碼」

這裏訪問它是在這裏

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

感謝

+0

如果您在Firefox中使用Firebug或使用Chrome Web Inspector,則可以使用'console.log(text);'輸出文本。 – 2013-02-16 09:39:53

回答

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

這應該工作。

+0

謝謝你做到了 – 2013-02-16 09:46:19