开发者

jquery- how should I extract value of href

ol class="result-list">
<li class="result item_1 odd first">
<h2>
<div class="number-description">
<div class="search-field c_patent_id">
<p class="value">
<a href="?mq=*%3A*&fa=c_application_type_name,owners,c_acquired_from,c_reference_number开发者_JAVA技巧,c_status_type_name,c_territory_name,c_patent_type_name,url,inventors,c_case_mgr_name&f=c_patent_id%5B%2283779616%22%5D">83779616</a>
</p>
</div>
</div>
<div class="search-field capsule c_patent_type_name">
<a class="poplight" rel="popup2" href="#">
</h2>
<div class="item-details">
</li>
<li class="result item_2 even">
<li class="result item_3 odd">
<li class="result item_4 even">
<li class="result item_5 odd">
<li class="result item_6 even">
<li class="result item_7 odd">
<li class="result item_8 even">
<li class="result item_9 odd">
<li class="result item_10 even last">
</ol>

This is the complete code and in this, every li tag has "a href tag" in the same way as previous li one(also same structure is follow- but I have expanded only first li tag-for reference) so now how can I extract the value of "a href, "


based on your exact code snippet:

var href = $('a').attr('href');

But if I were you I'd add an ID to your anchor tag and select it like so:

var href = $('#myId').attr('href');


$('a').attr('href') 

Should work. Of course you'll have to make sure you're grabbing the right


Add an id to your

var Href = $("a#specificLink").attr("href")


Or to set it would be

$('a#some-id').attr("href", "http://www.stackoverflow.com");

Edit:

I just tried

alert($('.testclass').attr("href"));

on a link I loaded with the href from your question (thinking that maybe the special characters or the fact that the href started with a ? was an issue) but I got the href back properly. Perhaps there is another issue in your environment?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜