html()文本上的JQuery CSS [英] JQuery CSS on html() text

查看:132
本文介绍了html()文本上的JQuery CSS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var data = $(span,this).html(); / * grab all * / 
$ calPopup.stop()。fadeTo(300,1);
$ calPopup.html(data);

我想做类似的操作:

  data.css(font-size,10pt); 

但是如果我这样做,html文本甚至不会出现。 Chrome的检查器说:

 未捕获TypeError:Object ***没有方法'css'



如何对文本应用CSS修改?

解决方案

.html() jQuery函数返回一个String,而不是一个jQuery对象,因此没有 .css()函数要使用。但是,如果你想把这个CSS样式应用到所有的< span> 元素,就像调用你的 .css / code>直接在选择他们的jQuery对象上:

  $('span',this).css ('font-size','10pt'); 



注意,我已经删除了变量声明,因为根据提供的代码,似乎没有必要。另请注意, .html()函数将仅返回第一个匹配元素的HTML,而不是所有元素的HTML,因此如果您有更多

若要解决编辑问题,请选择< span> 到问题:

  var data = $(span,this).clone()。css ','10pt'); 
$ calPopup.stop()。fadeTo(300,1);
$ calPopup.empty()。append(data);


var data = $("span", this).html(); /*grab all */
$calPopup.stop().fadeTo(300,1);
$calPopup.html(data);

I want to do something like:

data.css("font-size","10pt");

But if I do that, the html text doesn't even appear. Chrome's inspector says this:

Uncaught TypeError: Object *** has no method 'css' 

How can I apply a CSS modification to the text?

解决方案

The .html() jQuery function returns a String, not a jQuery object, so there's no .css() function to use. However, if you want to apply that CSS style to all of those <span> elements, it's as simple as calling your .css() function directly on the jQuery object that's selected them:

$('span', this).css('font-size', '10pt');

Note that I've removed the variable declaration because, based on the code provided, it seems unnecessary. Also note that the .html() function will return the HTML of the first matched element only, not all of them, so if you have more than one <span> element then you'll only get the HTML of the first.

To address edits to the question:

var data = $("span", this).clone().css('font-size', '10pt');
$calPopup.stop().fadeTo(300,1);
$calPopup.empty().append(data);

这篇关于html()文本上的JQuery CSS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆