Somehow grab this HTML? Not HTML Regex

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

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…

[code]

untitled document
  • title here random text here
    text
    25 likes
[/code]

coothead

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

$('.fsFacebookListItem').html('').append(a).append(extras);

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.