开发者

jquery get url from div and insert it into span

I would like to get the url from <div class="ms-vb itx"> and replace it into a href within a span below. Would that be doable in Jquery? does that make sense?

<td height="100%" class="ms-vb-title ms-vb-lastCell" onmouseover="OnChildItem(this)">
<div eventtype="" perm="0x7fffffffffffffff" field="LinkTitle" id="5" ctxname="ctx6" onmouseover="OnItem(this)" class="ms-vb itx">
<a target="_self" onclick="EditLink2(this,6);return false;" href="/_layouts/RF.Portal.Web/DetailActualite.aspx?4&amp;ListId={5B770E71-5269-4F45-87A0-2DEFA1136E40}&amp;ID=5&amp;ContentTypeID=0x0100FBEA8B5F8E1448F4B48C33A18522E2DA01001677EA3C9B9802408D15440E3B1906DE" onfocus="OnLink(this)">icitait l'honneur d'être reçu,</a>
<img class="ms-newgif" title="Nouveau" alt="Nouveau" src="/_layouts/1036/images/new.gif">
</div>
<div onmouseover="OnChildItem(this.parentNode); return false;" class="s4-ctx" style="top: 52px; left: 1015px; height: 105px; line-height: 105px; margin: 0px;">
<span>&nb开发者_StackOverflow社区sp;</span>
<a title="Menu Ouvrir" href="javascript:;" onclick="PopMenuFromChevron(event); return false;" onfocus="OnChildItem(this.parentNode.parentNode); return false;">
<img style="visibility: hidden;" src="/_layouts/images/ecbarw.png" alt="Menu Ouvrir"></a>
<span>&nbsp;
</span>
</div>
<span style="color: rgb(128, 128, 128);"><em>
          Publié le 07/03/2011 11:30 -
          En cours</em></span><br> et ayant nom Athos, Porthos et Aramis.   Nous l'avouons, ces trois noms étrange<br><br>
          <span style="font-size: 0.9em; color: rgb(128, 128, 128);" id="lireArticle">
          <a class="rfr-link-action" href="DispForm.aspx?ID=5">Lire l'article</a>
        <br><br></span>
        </td>


Sure, you just have to make sure that you select the right elements.

E.g.:

var $div = $('div.ms-vb.itx');
$div.next('span').find('a').attr('href', $div.find('a').attr('href'));

If you have more elements with these classes and you want to perform this for every of them, you can use each():

$('div.ms-vb.itx').each(function() {
    $(this).next('span').find('a').attr('href', $(this).find('a').attr('href'));
});

Update:

Ok, I assume you have several of these divs inside your table and you want to do this for all of them.

The a element you want to change seems to have a class rfr-link-action, so you can make use of this. Note, although your span element has an ID, IDs have to be unique in the document. No two elements can have the same ID.

$('div.ms-vb.itx').each(function() {
    $(this).closest('td') // gets a reference to the table cell
    .find('a.rfr-link-action') // finds the link
    .attr('href', $(this).find('a').attr('href')); // sets the URL
});


Try this:

url = $('.ms-vb a').attr('href');
$('#your_span_id a').attr('href', url);

But you should have a way to identify your div and span, e.g. add id attributes or smth.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜