Somehow grab this HTML? Not HTML Regex

  <li class="fsFacebookListItem">
    <span class="fsFacebookFrom">title here</span>&nbsp;random text here
    <div class="fsFacebookExtras fsStyleAutoclear">
      <img class="fsFacebookThumb" src="">
      <a target="_blank" class="fsFacebookTitle" href="link to fb post">text</a> 
      <div class="fsFacebookLikes">25 likes</div>

Is there a way to grab that nbsp/random text here and wrap that in an anchor that is the URL from the fsFacebookTitle element? I have found wrapInner which can wrap the entire element in an anchor, but doesn’t quite get the look I’m going for. So basically I need to know if I can wrap this / select it somehow.

<span class="fsFacebookFrom">title here</span>&nbsp;random text here

Note, I cannot change the HTML output listed above. Needs to be jQuery.

Hi there RyanReese,

does this help…


untitled document
  • title here random text here


As a possible approach, I think you can simply remove all childs from <li> so there will be only your random text left:

var item = $('.fsFacebookListItem');

$('.fsFacebookExtras', item).remove();
$('.fsFacebookFrom', item).remove();

var nbspRandomText = item.html();

Here is complete solution:

var item = $('.fsFacebookListItem').clone();
var extras = $('.fsFacebookExtras', item).clone();

$('.fsFacebookExtras', item).remove();

var text = item.html();

var href = $('.fsFacebookListItem a').attr('href');
var a = $('<a></a>').attr('href', href).html(text);


That’s brilliant. Didn’t think of that! Thanks coot / mega.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.