문제

After my using Bootstrap editable div I have some like this:

<span>
  Simple text
  <u>Hello!</u>
  Second text.  
</span>

All what I need - get all text from div, but if I use this recursive function, its return only content from elements, but text "Simple text" and "Second text" stay away from this function.

function parseElem(e){
  var r='';
  if(e.children('*').size()>0){
    e.children('*').each(function(){        
        r+=parseElem($(this));
    });
    return r;
  } else {
    return e.html().replace('<br>','\n');
  }    
}

And if I have

<span>
  He<b>ll</b>o!
  <p>
    <span>
      this
      <i>is</i>
      real
    </span>
    example  
  </p>
</span>

I want to leave tags i,u and stroke in returned value.

도움이 되었습니까?

해결책

This should filter the contents of your span down to your requirements. Just add any tags you do not want unwrapped to the :not() selector.

$('span').find(':not(b, i, u)').contents().unwrap();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top