jquery选择器中的帮助 [英] Help in jquery selectors
问题描述
您好,请参考以下HTML代码:
< div id =content>
< p>
< font size ='2'>
< img src =something.jpgwidth =500height =500/>
这是文本内容。这是文本内容。这是文本内容...
< / font>
< / p>
< / div>
这是从我的web应用程序的管理部分生成的html代码。我不能修改它,也不能改变上面代码的结构。它是动态生成的。
我需要使用jquery wrap()方法将文本内容包含在html元素中,以便我可以对文本内容放置一些css,而不是on img element。
注意:id为content的div元素是我自己的,我只能使用HTML访问此元素。
请帮助这样做?
感谢
这里是jQuery的方式
$(p& b $ b .contents()
.filter(function(){
return this.nodeType == 3;
})wrap('< span style =color:#FF0000 />');
您可以在这里演示 http://www.jsfiddle.net/K8WNR/
Hi please refer the following HTML code:
<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>
this is the html code which is being generated from admin section of my web application. I can't modify it and also can't change the structure of the above code. it is generating dynamically.
I need to wrap the text content in a html element using jquery wrap() method so that I can put some css on the text content and not on img element.
Note: The div element with id "content" is my own, I can access only this using HTML.
Please help how to do this?
Thanks
Here is the jQuery way
$("p > font")
.contents()
.filter(function() {
return this.nodeType == 3;
}).wrap('<span style="color:#FF0000" />');
You can Demo it here http://www.jsfiddle.net/K8WNR/
这篇关于jquery选择器中的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!