帮助jquery选择器

Bhu*_*upi 0 html javascript css jquery jquery-selectors

嗨,请参考以下HTML代码:

<div id="content">
    <p>
      <font size='2'>
        <img src="something.jpg" width="500" height="500" />
        this is the text content. this is the text content. this is the text content...
      </font>
    </p>
</div>
Run Code Online (Sandbox Code Playgroud)

这是从我的Web应用程序的管理部分生成的html代码.我无法修改它也无法更改上述代码的结构.它是动态生成的.

我需要使用jquery wrap()方法将文本内容包装在html元素中,以便我可以在文本内容上放置一些css,而不是在img元素上.

注意:id为"content"的div元素是我自己的,我只能使用HTML访问它.

请帮忙怎么做?

谢谢

Joh*_*ock 6

这是jQuery的方式

$("p > font")
  .contents()
  .filter(function() {
    return this.nodeType == 3;
  }).wrap('<span style="color:#FF0000" />');
Run Code Online (Sandbox Code Playgroud)

你可以在这里演示它 http://www.jsfiddle.net/K8WNR/